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
Trying to get data from db for Postobject and send it to Json format. PostComments is 1 to many relation of Post. i am using EF 5.x code first.
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();
}
.ToList()
before, JsonRequestBehavior.AllowGet
to force the evaluation earlier to try to figure out what part that is failing. - Albin Sunnanbo