I am learning EF and LINQ to EF. We are using LINQ Methods and not LINQ Expressions.
I am trying to do a very simple query from my 2 entities.
NavigationGroup is a one to many relation to NavigationGroupLocation. The Navigation Property in NavigationGroup is called "NavigationGroupLocations"
In my mind this code should work:
List<NavigationGroup> groups = db.DataModel.NavigationGroups.Where(g => g.NavigationGroupLocations.Location == 1).ToList();
Location is an int in my NavigationGroupLocation entity.
Can someone explain why this doesn't work and what the proper way to filter by a navigation property? I have seen many example in the expression syntax and can't seem to relate it to the method syntax.
I am using C# 4 & EF 4.
Thanks for the help!
EDIT
I see that since my Navigation Property is a collection I can't get to an individual property. So I am trying this code:
.Where(g => g.NavigationGroupLocations.Any(l => l.Location == 1));
When I try to run it I get this error:
Cannot implicitly convert type 'System.Linq.IQueryable<ME.Data.ECom.NavigationGroup>' to 'System.Data.Objects.ObjectSet<ME.Data.ECom.NavigationGroup>'. An explicit conversion exists (are you missing a cast?)
What should I be doing?