简体   繁体   English

如何在EF代码中首先添加没有加载导航的导航属性项?

[英]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 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});
}

你可以随时从另一边连接......

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EF4 Code First:如何在不添加导航属性的情况下添加关系 - EF4 Code First: how to add a relationship without adding a navigation property EF 延迟加载:将项目添加到导航属性而不加载它 - EF Lazy-Loading: Add item to navigation property without loading it 带有导航属性的Ef代码第一个索引,不添加ID - Ef Code first Index with navigation property without adding Id EF的代码优先,如何在不设置数据库表之间外键的情况下定义导航属性关系 - Code first of EF, how to define navigation property relationship without setting foreign key between table in database EF4.1代码优先:如何在依赖实体中禁用没有导航属性的关系的删除级联 - EF4.1 Code First : How to disable delete cascade for a relationship without navigation property in dependent entity EF代码优先如何使用Entity检索导航属性? - EF code-first how to retrieve navigation-property with Entity? OData和EF 6代码优先导航属性问题 - OData and EF 6 Code first navigation property issue 在EF 5中定义导航属性,代码优先迁移 - Defining a Navigation property in EF 5, Code first migrations EF代码第一个单向导航属性 - EF Code first one way navigation property EF Code First属性到同一个表 - EF Code First Navigation Property to same table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM