小编Cur*_*ive的帖子

然后在实体框架核心中包含显式加载?

我知道我可以更深入地使用ThenIncludeEager Loading加载相关数据,如下例所示

//Eager Loading
var publisher = await _context.Publishers
                              .Include(pub => pub.Books)
                                  .ThenInclude(book => book.Sales)
                              .Include(pub => pub.Users)
                              .Where(pub => pub.PubId == id)
                              .FirstOrDefaultAsync();
Run Code Online (Sandbox Code Playgroud)

如何在显式加载中编写相同的查询?Sales在下面的情况下,如何在不循环阅读书籍的情况下加载数据?

//Explicit Loading
var publisher = await _context.Publishers
                              .SingleAsync(pub => pub.PubId == id);

_context.Entry(publisher)
        .Collection(pub => pub.Books)
        .Load();
                 
_context.Entry(publisher)
        .Collection(pub => pub.Users)                
        .Load();
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework entity-framework-core .net-core

7
推荐指数
1
解决办法
571
查看次数