如何使用Linq包含一个集合的两个集合



我有一个DBSet,它有一个我想包含的集合。这个集合有两个我想要包含的对象。如果我在第一个中使用。theninclude,那么我似乎无法得到一个能够包含第二个的引用。

var a = _context.ModelA.Include(x => x.CollectionB).ThenInclude(x => x.ObjectC)

.Include(x =>x.ObjectD)//也属于CollectionB

多重包含在EFCore中不存在,你必须这样做

var a = _context.ModelA
.Include(x => x.CollectionB).ThenInclude(x => x.ObjectC)
.Include(x => x.CollectionB).ThenInclude(x => x.ObjectD)

最新更新