Joining tables in EF Core Linq Query

asp.net-core-webapi entity-framework-core linq linq-query-syntax

Accepted Answer

Simply use to obtain the posts with comments (and the user of each remark) and post users..Include()

var res = this._dbContext.Posts
        .Include(p => p.User)
        .Include(p => p.Comments)
            .ThenInclude(c => c.User)
        .ToList();

enter image description here

If you choose not to add a third-party library suchAutoMapper you can build aconvertPostToDto both use and function.

p => convertPostToDto(p) res.Select

to change theres as a consequence

2
10/25/2018 8:58:44 AM






Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow