2

以下のエラーが発生する

LINQ to Entities はメソッド 'System.Object get_Item(System.String)' メソッドを認識せず、このメソッドはストア式に変換できません

Postobject の db からデータを取得し、Json 形式で送信しようとしています。PostComments は、Post の 1 対多の関係です。最初に 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();
        }
4

1 に答える 1