简体   繁体   English

LINQ to Entities无法识别方法'System.Object get_Item(System.String)'

[英]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.

相关问题 LINQ to Entities 无法识别“System.Object get_Item(System.String)”方法 - LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)' method LINQ to Entities 无法识别方法“System.Object get_Item(System.String)”方法无法转换为存储表达式 - LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)' method cannot be translated into a store expression LINQ to Entities无法识别方法&#39;System.String get_Item(System.String)&#39;, - LINQ to Entities does not recognize the method 'System.String get_Item (System.String)', LINQ to Entities 无法识别“System.String get_Item(Int32)”方法 - LINQ to Entities does not recognize the method 'System.String get_Item(Int32)' method Linq to entities无法识别system.string get_Item方法 - Linq to entities does not recognize the method system.string get_Item LINQ to Entities无法识别方法&#39;Newtonsoft.Json.Linq.JToken get_Item(System.String)&#39;方法, - LINQ to Entities does not recognize the method 'Newtonsoft.Json.Linq.JToken get_Item(System.String)' method, LINQ to Entities无法识别方法&#39;System.String get_Item(Int32)&#39;,并且该方法无法转换为商店表达式 - LINQ to Entities does not recognize the method 'System.String get_Item(Int32)' method, and this method cannot be translated into a store expression LINQ to Entities无法识别方法&#39;System.Object Parse(System.Type,System.String)&#39; - LINQ to Entities does not recognize the method 'System.Object Parse(System.Type, System.String)' LINQ 实体无法识别方法 '<>f__AnonymousType4`1[System.String] get_Item(Int32)' - LINQ to Entities does not recognize the method '<>f__AnonymousType4`1[System.String] get_Item(Int32)' LINQ to Entities无法识别方法&#39;System.String Concat(System.Object)&#39;方法, - LINQ to Entities does not recognize the method 'System.String Concat(System.Object)' method,
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM