是否可以使用现有的Child Ids显式重新加载Reload()
中DbEntityEntry
的功能?另见代码中的注释。
using (var context = new MyContext())
{
var parent = new Parent()
{
ParentId = 1,
Childs = new List<Child>()
{
new Child()
{
ChildId = 2,
ParentId = 1
}
}
};
context.Parents.Attach(parent);
context.Entry(parent)
.Collection(b => b.Childs) // Load only Employee with employee id of 2
.Query()
.Load(); //Is it possible to Reload only ChildId = 2?
}
答案 0 :(得分:1)
是的,可以在Query
方法之后将过滤器应用于您要加载的相关实体:
context.Entry(parent)
.Collection(b => b.Childs) // Load only Employee with employee id of 2
.Query()
.Where(e=>e.ChildId==2)
.Load();