asp.net-mvc-3 – EF 4.1 – 模型关系
发布时间:2020-12-15 18:40:46 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试使用RC 4.1版本创建一个快速的ASP.NET MVC 3应用程序。我有两个型号: public class Race{ public int RaceId { get; set; } public string RaceName { get; set; } public string RaceDescription { get; set; } public DateTime? RaceDate { get
我正在尝试使用RC 4.1版本创建一个快速的ASP.NET MVC 3应用程序。我有两个型号:
public class Race { public int RaceId { get; set; } public string RaceName { get; set; } public string RaceDescription { get; set; } public DateTime? RaceDate { get; set; } public decimal? Budget { get; set; } public Guid? UserId { get; set; } public int? AddressId { get; set; } public virtual Address Address { get; set; } } 和 public class Address { public int AddressId { get; set; } public string Street { get; set; } public string StreetCont { get; set; } public string City { get; set; } public string State { get; set; } public string ZipCode { get; set; } public virtual Race Race { get; set; } } 尝试插入新的比赛时,我收到以下错误:
不应该将RaceId作为Races表和AddressId的主键识别为地址表的FK吗?我缺少什么? 谢谢! 解决方法
这里的问题似乎是EntityFramework无法识别前导键的位置,因为您在两个对象中都保存交叉引用。不确定你想要实现什么,我可能会建议这样:
public class Race { public int RaceId { get; set; } public string RaceName { get; set; } public string RaceDescription { get; set; } public DateTime? RaceDate { get; set; } public decimal? Budget { get; set; } public Guid? UserId { get; set; } public int? AddressId { get; set; } public virtual Address Address { get; set; } } public class Address { public int AddressId { get; set; } public string Street { get; set; } public string StreetCont { get; set; } public string City { get; set; } public string State { get; set; } public string ZipCode { get; set; } } 在第二个实体中跳过参考。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 向ASP.NET Gridview添加动态列
- asp.net web api定义的b/s调用方法一例
- asp.net-mvc – 在MVC Action中将SSRS报告导出为PDF
- asp.net – 防止将父web.config继承到IIS 7.5上的子应用程序
- asp.net – 操作无法完成. FORMATETC结构无效
- 这是一个bug?浮动操作被视为整数
- asp.net – VB.NET 2.0:代码中的URL来自哪里?
- ASP.NET MVC 3:我可以将C#Razor Views与F#控制器结合使用吗
- asp.net-mvc-3 – 如何在MVC3中将附加列添加到WebGrid中
- 处理ASP.Net MVC中的过期标题
推荐文章
站长推荐
热点阅读