C# EF将实体序列化为json,并包含相关实体以创建循环

C# EF将实体序列化为json,并包含相关实体以创建循环,c#,json,entity-framework,asp.net-web-api,serialization,C#,Json,Entity Framework,Asp.net Web Api,Serialization,我在我的WebApi项目中使用EF。我有一个数据库,包括许多相互关联的表。当我序列化来自表的对象时,它会创建一个奇怪的json 我的EF查询如下所示 db.Products.Include(x => x.ProductCategoryRelations) .Include(x => x.ProductCategoryRelations.Select(c => c.Category)) .Include(x => x.ProductFileRelations) .Inclu

我在我的WebApi项目中使用EF。我有一个数据库,包括许多相互关联的表。当我序列化来自表的对象时,它会创建一个奇怪的json

我的EF查询如下所示

db.Products.Include(x => x.ProductCategoryRelations)
.Include(x => x.ProductCategoryRelations.Select(c => c.Category))
.Include(x => x.ProductFileRelations)
.Include(x => x.ProductFileRelations.Select(c => c.File))
.Include(x => x.ProductPropertyRelations)
.Include(x => x.ProductPropertyRelations.Select(c => c.Property))
.Include(x => x.ProductColorRelations)
.Include(x => x.ProductColorRelations.Select(c => c.Color))
.Include(x => x.Brand)
.Where(predicate)
.ToListAsync();
因为这个EF查询。它创建了一个json,如下所示,这是不可接受的

1.Product
    2.Brand
        3.Product
            4.ProductCategoryRelations
                5.Product
                    .....
                    .....
                    .....
                    .....
我怎样才能解决这个问题?我想有一系列的产品,但我不是什么,我需要改变,以获得这样的结果。任何帮助都将不胜感激

提前感谢

尝试以下方法:

db.Products
.Where(predicate)
.Select(p=> new { p.Brand, p.ProductColor.Color_Name, p.ProductCategory.Category_Name })
.ToListAsync();