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.Creat开发者_如何学运维eDate 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.
var q = from u in ProjectDBEntities.Users
from f in u.Favorites
where f.User.Id == 3
orderby f.CreateDate desc;
I'm making some presumptions about your entity model/property names since you don't show it, but this should give you the general idea.
精彩评论