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});
精彩评论