[英]LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)'
getting error below 在下面出现错误
LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)' method, and this method cannot be translated into a store expression
LINQ to Entities无法识别方法'System.Object get_Item(System.String)',并且该方法无法转换为商店表达式
Trying to get data from db for Postobject and send it to Json format. 尝试从db获取Postobject的数据并将其发送为Json格式。 PostComments is 1 to many relation of Post.
PostComments是Post的一对多关系。 i am using EF 5.x code first.
我首先使用EF 5.x代码。
try
{
IEnumerable<Post> userPosts;
userPosts = (from q in db.Posts
where q.UserId == userId
&& q.PostId > postid
select q).Take(5);
return Json(userPosts.Select(x => new
{
success = 1,
contenttext = x.PostContent,
postId = x.PostId,
comments = x.PostComments //is a child collection object
}), JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
return Json(new { success = 0 });
}
finally
{
//db.Dispose();
}
I am not sure if you have already tried this. 我不确定您是否已经尝试过。
return Json(userPosts.Select(x => new
{
success = 1,
contenttext = x.PostContent,
postId = x.PostId,
comments = x.PostComments //is a child collection object
}).ToList(), JsonRequestBehavior.AllowGet);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.