asp.net-mvc-3 – EF 4.1 – 模型关系
发布时间:2020-05-29 18:22:23 所属栏目: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; } pub
|
我正在尝试使用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 dev服务器和IIS Express有什么区别?
- asp.net-mvc-4 – AngularJs,DropZone.Js,MVC4 – 拖放,预览
- asp.net-mvc – ASP.NET MVC Route,在控制器之前具有值,没有
- asp.net-mvc – asp.net mvc 4 – 谁调用_ViewStart.cshtml
- asp.net-mvc – ASP.NET MVC – 从查询字符串中获取对象列表
- asp.net-core – ASP.Net核心maxUrlLength
- asp.net – .resx vs数据库vs用于提供本地化/全球化的自定义
- asp.net-mvc – FormsAuthentication LoginUrl
- asp.net-mvc-3 – 如何在VIEW MVC3 Razor中显示webforms页面
- 在asp.net中输入密钥发出错误按钮
推荐文章
站长推荐
- asp.net – Web开发人员可以使用最好的HTML WYSI
- asp.net – “HttpContext.Current.Session”vs
- asp.net – AngularJs 2与ASP.NET 4.5.1
- asp.net-mvc – 值不能为空或为空.参数名称:con
- asp.net – Web API中的每路径格式化程序配置
- asp.net-mvc – 为什么我的ActionFilters都没有运
- 安装程序 – 无法安装ASP.NET MVC3 RTM?
- asp.net – Visual Studio可以在新的调试会话中重
- asp.net-mvc – Ninject和连接字符串
- ASP.NET清空缓存时遇到的问题简析
热点阅读
