在VS2008中,我认为是EF1.0,这很好用。
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);
VS2010 EF4 中的相同代码在 foreach 循环中崩溃并出现以下错误:
查询的结果类型既不是 EntityType 也不是具有实体元素类型的 CollectionType。只能为具有这些结果类型之一的查询指定包含路径。