我正在将ASP.Net Core 2.0与Entity Framework一起使用,并且试图将模型返回到包含Employment实体的页面,该页面还包含了EmploymentDocument实体.对于后者,我不想加载data(byte [])列,但我希望所有其他列,最重要的是FileName.
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 entities also included. For the latter I do not want to load the data (byte[]) column but I do want all the other columns, most importantly FileName.
我具有的linq查询,其中加载了包括data列在内的所有内容:
The linq query I have which loads everything including the data column is:
var employment = await _context.Employment .Include(e => e.EmploymentDocuments) // will load all associated document data .SingleOrDefaultAsync(m => m.EmploymentID == id);此处的目的是能够在页面上显示所有文档名称的列表,并带有链接,然后可以使用这些链接来下载所选文件的数据.
The purpose here is to be able to show a list of all the document names on the page with links that can then be used to download the data for the file selected.
推荐答案手动选择所需的所有数据并将其存储在某些Dto对象中:
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();更多推荐
EF Core LINQ从包含的实体中排除列
发布评论