asp.net-mvc – MVC 4,Upshot实体循环引用
发布时间:2020-12-15 23:53:25 所属栏目:asp.Net 来源:网络整理
导读:我有一个DbDataController,它提供了一个设备列表. public IQueryableBettrFit.Models.Equipment GetEquipment() { var q= DbContext.EquipmentSet.OrderBy(e = e.Name); return q; } 在我的脚手架视图中,一切看起来都不错. 但是Equipment包含EquipmentType的
我有一个DbDataController,它提供了一个设备列表.
public IQueryable<BettrFit.Models.Equipment> GetEquipment() { var q= DbContext.EquipmentSet.OrderBy(e => e.Name); return q; } 在我的脚手架视图中,一切看起来都不错. 但是Equipment包含EquipmentType的HashSet成员.我想在我的视图中显示此类型,并且还能够将数据添加到Equipment的EquipmentType集合中(通过多选列表). 但是如果我尝试在我的linq查询中包含“EquipmentType”,它会在序列化期间失败. public IQueryable<BettrFit.Models.Equipment> GetEquipment() { var q= DbContext.EquipmentSet.Include("EquipmentType").OrderBy(e => e.Name); return q; } “类型EquipmentType的对象图包含循环,如果禁用参考跟踪则无法序列化” 如何打开“回溯引用”? 也许问题是EquipmentType是通过HashSet反向链接的?但我在查询中没有.include(“EquipmentType.Equipment”).所以那应该没问题. Upshot如何生成模型?我只找到了EquipmentViewModel.js文件,但这不包含任何模型成员. 这是我的模型类: public class Equipment { public Equipment() { this.Exercise = new HashSet<Exercise>(); this.EquipmentType = new HashSet<EquipmentType>(); this.UserDetails = new HashSet<UserDetails>(); } public int ID { get; set; } public string Name { get; set; } public string Description { get; set; } public string Picture { get; set; } public string Link { get; set; } public string Producer { get; set; } public string Video { get; set; } public virtual ICollection<EquipmentType> EquipmentType { get; set; } public virtual ICollection<UserDetails> UserDetails { get; set; } } public class EquipmentType { public EquipmentType() { this.Equipment = new HashSet<Equipment>(); this.UserDetails = new HashSet<UserDetails>(); } public int ID { get; set; } public string Name { get; set; } public string Description { get; set; } public virtual ICollection<Equipment> Equipment { get; set; } public virtual ICollection<UserDetails> UserDetails { get; set; } } 解决方法
尝试使用[IgnoreDataMember]装饰其中一个导航属性
[IgnoreDataMember] public virtual ICollection<Equipment> Equipment { get; set; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 使用Booksleeve维护开放的Redis PubSub订阅
- Asp.net,paypal和IPN ..如何自动付款?
- asp.net – 登录后对Membership.GetAllUsers()的例外情况:
- Refit在ASP.NET Core中的实践
- asp.net – Silverlight中的多任务处理和多线程处理
- IIS ASP.NET WebApi在请求同一台服务器时死锁
- asp.net-mvc-4 – signalR:/ signalr/hubs不生成
- asp.net – 无法让AsyncFileUpload在更新面板中工作
- asp.net – ObjectDataSource删除问题
- asp.net-mvc – 用于加密的MVC AntiForgeryToken机器密钥
推荐文章
站长推荐
- asp.net – HttpContext.Current.User.Identity.
- asp.net – 从ASP .Net下载文件时,文本文件会附加
- 初识ABP vNext(11):聚合根、仓储、领域服务、
- asp.net-mvc-3 – 使用表单身份验证的MVC3中的简
- asp.net-mvc – 是否可以在IIS服务器上部署asp.n
- asp.net – 使用Web API和JSON补丁文档进行模型验
- asp.net-mvc – ASP.NET MVC帐户控制器使用指南?
- asp.net-mvc – ASP.NET Web优化 – 无需捆绑即可
- asp.net – 兼容模式下的IE9无法正确显示CSS样式
- asp.net – 在启用了共享配置的IIS 7上安装Web D
热点阅读