Reputation: 862
I am sure I could google this if I knew what to search for, if that makes sense. I'm trying to get the hang of entity framwork, and considering how i would implement some real-world scenarios in it.
Imagine a simple data model with a Person entity, and a Color entity, and an association called ColorsLiked.
I want to use Color a bit like an enum; there will only be 3 defined (red, green, blue).
I want a drop-down to allow the used to add Colors to their list of colors they like - which is all easy enough. But, what query can I use to select only the colors the person doesn't already like? i.e so that as they pick a color, it is no longer available for selection in the list.
In SQL, it's a simple query with a left outer join. But I don't understand how to do something like this in EF.
any guidance would be appreciated
slip
Upvotes: 0
Views: 88
Reputation: 402
Assuming that you want all the colors the person has not yet liked this is the LINQ expression to do that.
var unlikedColors = allColors.Except(person.ColorsLiked);
Upvotes: 1