如何在 Entity Framework 4 中查询实体
在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。只能为具有这些结果类型之一的查询指定包含路径。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在对您的实体模型/属性名称做出一些假设,因为您没有显示它,但这应该为您提供总体思路。
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.