EF Core LINQ exclude column from included entity

前端 未结 1 1697
你的背包
你的背包 2021-01-24 16:17

I\'m using ASP.Net Core 2.0 with Entity Framework and I am trying to return a model to a page that contains the Employment entity with it\'s collection of EmploymentDocument ent

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-24 16:32

    Select all data you need by hands and store it in some Dto object:

    var employment = await _context.Employment
        .Where(m => m.EmploymentID == id)
        .Select(e => new EmploymentDto
        { 
            ID = e.EmploymentID,
            Docs = e.EmploymentDocuments.Select(o => o.FileName)
        })
        .SingleOrDefaultAsync();
    

    0 讨论(0)
提交回复
热议问题