How to query Entities in Entity Framework 4
- by Picflight
In VS2008, I think it is EF1.0, this works just fine.
string queryString = @"SELECT VALUE USERS FROM ProjectDBEntities.Users AS User
INNER JOIN ProjectDBEntities.Favorites AS F ON F.FavUserId = User.UserId
WHERE F.UserId = " + 3 + " ORDER BY F.CreateDate DESC ";
System.Data.Objects.ObjectQuery<User> usersQuery =
new System.Data.Objects.ObjectQuery<User>(queryString, context).Include("Detail");
//int count = usersQuery.Count();
foreach (User result in usersQuery)
Console.WriteLine("User Name: {0}", result.UserName);
Same code in VS2010 EF4 it crashes on the foreach loop with the following error:
The result type of the query is neither an EntityType nor a CollectionType with an entity element type. An Include path can only be specified for a query with one of these result types.