Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用包含的实体框架-从链接实体中排除某些列_C#_Json_Entity Framework Core - Fatal编程技术网

C# 使用包含的实体框架-从链接实体中排除某些列

C# 使用包含的实体框架-从链接实体中排除某些列,c#,json,entity-framework-core,C#,Json,Entity Framework Core,我有一个查询返回一个配置,如下所示: public JsonResult Configurations(int id) { var myConfiguration = dbContext.MyEntity .Where(e => e.Id == id)

我有一个查询返回一个
配置
,如下所示:

    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中包含该属性,
Configuration孙辈
每个人都有一个
Client
属性,我不想包含该属性。如何排除它们?

尝试在客户端属性上方添加[JsonIgnore]

配置.cs
不能排除通过EF Core导航属性修复填充实体导航属性,因为它们是EF Core必须维护的模型不变量的一部分。但是,您可以使用相应序列化程序提供的控件从序列化中排除任何内容。或者不使用实体进行序列化,而是使用投影DTO。请参阅EF核心文档部分。谢谢@Ivan Stoev。你有没有一个我如何在我的案例中实现这一点的例子?在建模文件夹上不美观。然后包括(entity=>new EntitylyTo{/*映射此处所需的属性,如Property1=entity.Property*/})
public class Configuration
{
     [JsonIgnore]
     public string Client { get; set; }

}