EF Core LINQ从包含的实体中排除列

编程入门 行业动态 更新时间:2024-10-21 14:34:24
本文介绍了EF Core LINQ从包含的实体中排除列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在将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从包含的实体中排除列

本文发布于:2023-11-14 04:29:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586222.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实体   EF   Core   LINQ

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!