开发者

How to add navigation property item without load navigations in EF code first?

I am able to add comment to user like in below. But I have some开发者_Python百科 suspection that when i access Posts navigations so all navigations are loaded if so how i can add comment to user without load it ?

public void Add(int userId,string comment)
{
   var user = dbcontext.Users.Find(userId);
   user.Posts.Add(new Comment{Commentbody=comment});
}


You can always connect it from the other side...

dbcontext.Comments.Add(new Comment{Commentbody=comment, User=user});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜