I've been searching all day and can't find a solution to this...
I have an EntityCollection
of Communication
objects which each have an instance of an Intention
object(one-to-one).
I also have a User
object which has many instances of UserLocation
EntityObjects
(one-to-many)
Intention
objects have a propertyUID
.UserLocation
objects have a propertyLID
.I want to write a LINQ expression which returns all
Communication
objects where theUID
property of theIntention
instance associated to aCommunication
object equals ANYLID
property of ANY instance of aUserLocation
instance for aUser
object.
I've tried this
return _context.Communications.Where
(u => u.Intention.UID.Equals
(user.UserLocations.Select
(p => p.LID)));
and this
return _context.Communications.Where
(u => user.UserLocations.Any
(x => x.LID.Equals
(u.Intention.UID)));
and this
var thislist = from Intentions in _context.Intentions
join UserLocations in user.UserLocations
on Intentions.UID equals UserLocations.LID
select Intentions.UID;
return _context.Communications.Where(u => u.Intention.Equals(thislist.Any()));
and this
var lidlist = user.UserLocations.Select(x => x.LID);
return _context.Communications.Where(x=> lidlist.Contains(x.Intention.UID)).ToList();
(this gives me an error on the Contains statement saying "Delegate System.Func<Communication,int,bool>
does not take 1 argument", don't know how to fix)
Along with all these variations I have also:
- modified my method to return
IQueryable<Communication>
and have also triedList<Communication>
while appendingToList()
to my queries.
Nothing works. Regardless of what I try I always end up with this exception
NotSupportedException was unhandled by user code
Unable to create a constant value of type 'PreparisCore.BusinessEntities.UserLocation'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
What am i doing wrong??
Where(x=> lidlist.Contains(x.Intention.UID))
anything is spelled wrong, for example:lidxyzlist
orContain
orIntenton
orAID
or... The message is very strange because it doesn't say "this or that variable/property is undeclared which I had expected. But if I fix all spelling errors it compiles (and I believe it will run correctly without exception then). Can you double check if everything is written correctly? – Studiox => lidlist.Contains(x.Intention.UID))
– Lawry