邮递员无法从M到N集合接收JSON

时间:2018-11-09 08:54:34

标签: mysql .net-core postman

我正在尝试从邮递员获得具有M对N关系的Collection的HTTP响应。表的类如下所示。

电影表

public partial class Film
    {
        public Film()
        {
            FilmActor = new HashSet<FilmActor>();
            FilmCategory = new HashSet<FilmCategory>();
            Inventory = new HashSet<Inventory>();
        }

        //Some Properties


        public ICollection<Inventory> Inventory { get; set; }
    }

链接表清单

public partial class Inventory
    {
        public Inventory()
        {
            Rental = new HashSet<Rental>();
        }

        public int InventoryId { get; set; }
        public short FilmId { get; set; }
        public byte StoreId { get; set; }
        public DateTimeOffset LastUpdate { get; set; }

        public Film Film { get; set; }
        public Store Store { get; set; }
        public ICollection<Rental> Rental { get; set; }
    }

存储表

public partial class Store
    {
        public Store()
        {
            Customer = new HashSet<Customer>();
            Inventory = new HashSet<Inventory>();
            Staff = new HashSet<Staff>();
        }

        //More Properties
        public ICollection<Inventory> Inventory { get; set; }

    }

我尝试将整个收藏集显示在Postman上。 VS在“本地”窗口中返回的对象包含759个对象。在MySql数据库上,我有2270。

这是我的存储库中的查询

return _context.Film
                .Include(x => x.Inventory)
                .Where(x => x.Inventory.Any(c => c.StoreId == storeId))
                .ToList();

我在Postman上收到此错误。

enter image description here

我还尝试对查询应用分页,因为我认为服务器可能不支持要查询的对象数量。所以我一次只能得到10个对象。 VS在“本地”窗口中向我显示了10个对象。

这是我的查询

 return _context.Film
                .Include(x => x.Inventory)
                .Where(x => x.Inventory.Any(c => c.StoreId == storeId))
                .Skip(filmsResourceParameters.PageSize 
                * (filmsResourceParameters.PageNumber -1))
                .Take(filmsResourceParameters.PageSize)
                .ToList();

我得到同样的邮递员错误: enter image description here

这是我的邮递员设置:

enter image description here

1 个答案:

答案 0 :(得分:0)

结果证明Dto不能具有包含链接表的Collection,因为这将导致无法以JSON表示的循环依赖关系。我再也无法解释了。如果有人可以更详细地解释它,请随意这样做,因为我想了解wtf正在进行中。