MVC3 Model中有两个主键时出现:Unable to determine composite primary key ordering for type错误的解决办法

简介: 比如: public class LineItem { [Key] public int OrderId { get; set;} [Key] public int LineNum { get; set;} ...

比如:

 public class LineItem
    {
        [Key]
        public int OrderId { get; set;}
        [Key]
        public int LineNum  { get; set;}
        public string ItemId { get; set;}
        public int Quantity { get; set;}
        public decimal UnitPrice { get; set; }

    }

编译时会出现如下错误:Unable to determine composite primary key ordering for type *****Use the ColumnAttribute or the HasKey method to specify an order for composite primary keys.

解决办法是给主键加上顺序:

分别加上:[Column(Order = 0)] and [Column(Order = 1)]

学习交流群:364976091
相关文章
|
API 数据库 前端开发
MVC中数据库表如果是一对一的主键关系时要加[Required]不然会出错Unable to determine the principal end of an association between the types
Unable to determine the principal end of an association between the types '***. The principal end of this association must be explicitly configured us...
686 0
|
3月前
|
开发框架 前端开发 .NET
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
42 0
|
8月前
|
存储 开发框架 前端开发
[回馈]ASP.NET Core MVC开发实战之商城系统(五)
经过一段时间的准备,新的一期【ASP.NET Core MVC开发实战之商城系统】已经开始,在之前的文章中,讲解了商城系统的整体功能设计,页面布局设计,环境搭建,系统配置,及首页【商品类型,banner条,友情链接,降价促销,新品爆款】,商品列表页面,商品详情等功能的开发,今天继续讲解购物车功能开发,仅供学习分享使用,如有不足之处,还请指正。
117 0
|
9月前
|
开发框架 前端开发 .NET
[回馈]ASP.NET Core MVC开发实战之商城系统(三)
[回馈]ASP.NET Core MVC开发实战之商城系统(三)
67 0
|
9月前
|
开发框架 前端开发 .NET
[回馈]ASP.NET Core MVC开发实战之商城系统(一)
[回馈]ASP.NET Core MVC开发实战之商城系统(一)
113 0
|
9月前
|
SQL 开发框架 前端开发
[回馈]ASP.NET Core MVC开发实战之商城系统(开篇)
[回馈]ASP.NET Core MVC开发实战之商城系统(开篇)
144 0
|
9月前
|
开发框架 缓存 JSON
ASP.NET Core MVC 从入门到精通之Filter
ASP.NET Core MVC 从入门到精通之Filter
120 0
|
9月前
|
开发框架 前端开发 .NET
ASP.NET Core MVC 从入门到精通之自动映射(二)
ASP.NET Core MVC 从入门到精通之自动映射(二)
60 0
|
5月前
|
开发框架 自然语言处理 前端开发
基于ASP.NET MVC开发的、开源的个人博客系统
基于ASP.NET MVC开发的、开源的个人博客系统
52 0
|
8月前
|
SQL 开发框架 前端开发
[回馈]ASP.NET Core MVC开发实战之商城系统(完:内附源码)
经过一段时间的准备,【ASP.NET Core MVC开发实战之商城系统】已经完成,目前代码已开发完成,先将全部内容整理分享,如有不足之处,还请指正。
107 0