asp.net-mvc – MVC 4,Upshot实体循环引用
发布时间:2020-05-25 05:30:42 所属栏目:asp.Net 来源:互联网
导读:我有一个DbDataController,它提供了一个设备列表. public IQueryableBettrFit.Models.Equipment GetEquipment() { var q= DbContext.EquipmentSet.OrderBy(e = e.Name); return q; } 在我的脚手架视图中,一切看起来都不错. 但
|
我有一个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-mvc – MVC 5脚手架不为基本EF派生数据发出引导类
- asp.net-mvc – 我们可以在Controller中创建静态ActionResu
- asp.net – 使用MySql和MVC 3上的成员资格向注册表单添加更
- asp.net – 会话 – 多个浏览器选项卡 – 不同的会话?
- asp.net – executionTimeout和Server.ScriptTimeout之间的
- asp.net-core – 如何在ASP.NET Core中共享汇编信息?
- asp.net-mvc – ASP.NET MVC应用程序的WatiN最佳实践/经验法
- asp.net – 如何使用JQuery与母版页?
- Owin错误与ASP.NET MVC应用程序
- asp.net-mvc – MVC4是否被烘烤到.NET 4.5?
推荐文章
站长推荐
- asp.net-mvc – 尝试将asp.net web发布到Azure时
- asp.net – 如何停止插入两次的配置转换插件?
- 单元测试 – 使用MOQ对象进行ASP.NET MVC单元测试
- asp.net-mvc – OnActionExecuting(FilterExecut
- asp.net – ‘WebForm_DoPostBackWithOptions’在
- asp.net-mvc-4 – 如何在mvc4中将Json字符串发送
- asp.net – 将ViewModel从演示文稿传递到服务 –
- asp.net-mvc – 防止加载部分视图
- asp.net-mvc – 为什么需要为Html.Action定义的路
- asp.net – 无法加载文件或程序集System.Web.Htt
热点阅读
