c# - 使用 ThenInclude 的实体框架 - 从链接实体中排除某些列
问题描述
我有一个查询返回Configuration
如下所示:
public JsonResult Configurations(int id)
{
var myConfiguration = dbContext.MyEntity
.Where(e => e.Id == id)
.Include(e => e.Group)
.ThenInclude(g => g.Configuration)
.ThenInclude(c => c.ConfigurationChildren)
.ThenInclude(cc => cc.ConfigurationGrandchildren)
.FirstOrDefault();
.Group?
.Configuration;
return Json(myConfiguration);
}
Configuration
有一个Client
我不想包含在返回的 Json 中的属性,并且每个ConfigurationGrandchildren
都有一个Client
我不想包含的属性。我如何排除它们?
解决方案
尝试在 Client 属性上方添加 [JsonIgnore]。
配置.cs
public class Configuration
{
[JsonIgnore]
public string Client { get; set; }
}
推荐阅读
- javascript - 如何在 javascript 中使用 plotly 在图像上绘制热图?
- esp32 - ESP32 xTaskGetTickCount 不返回正确的值
- java - 使用 getResource() 从资源文件夹获取文件时出现 FileNotFoundException
- python - 请纠正我。我写的代码在笔记本里
- c++ - C++ 将文本从 .txt 文件解析为变量
- python-3.x - 具有深度分析技能的 PDF 爬虫
- winapi - 如何将包含 ComPtr 值的类插入到
- javascript - 如何在 Google 电子表格上使用 IMPORTXML 获取股票的上市前价值?
- python - 抓取最初隐藏并在提交后出现的数据
- c# - 等待来自服务器 .net Tcp 的数据