G
G
groulls2020-09-13 20:09:20
ASP.NET
groulls, 2020-09-13 20:09:20

How to implement Linq query by converting entities to DTO?

How to pull the values ​​of entity B?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2020-09-14
@yarosroman

Automapper to help you

V
Vasily Bannikov, 2020-10-28
@vabka

Nifiga did not understand what you want.
Pulled the request from the change history, corrected it a bit

await _context.A.Include(a => a.B)
                .ThenInclude(a => a.C)
                .Where(a => a.Id == 1)
                .Select(a => new ADto
                       {
                           Id = a.Id,                                                  
                           C = a.C.Select(c => new CDto { Id = c.Id, Name = c.Name}).ToList(),											 
                           B = new BDto { Id = a.B.Id, Name = a.B.Name }
                       })
                     .SingleAsync();

As I understand it, you want to recursively map values ​​from the BA sheet - this is a very bad idea and I would advise you to think about how you can do without it (for example, you can implement Lazy loading and give the client the value of this sheet only when the client opens some list)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question