【发布时间】:2014-06-05 14:29:36
【问题描述】:
当我向表中添加新实体时,我希望在保存更改后填充导航属性。我该怎么做?
这就是我现在正在做的事情,导航属性 Condition 为空。我检查了外键是否已设置。我还尝试通过直接从另一个表中读取来手动分配 nav 属性,但即使这样也不起作用。
...
var group = _context.Groups.AddRange(groups).First();
await _context.SaveChangesAsync();
// group.Condition which is a navigation property is null after this.
// The property does work when I get the group from the context, after adding.
【问题讨论】:
-
你试过
var group = _context.Groups.AddRange(groups).First().Include(x=>x.Condition); -
那行不通,甚至不能在那里使用 Include。在保存后更新我使用 Include 的实体。
标签: c# entity-framework navigation-properties