EF Codefirst 无法处理 Northwind 数据库的部分表
我无法单独使用 Northwind 数据库的员工表。
下面的代码抛出错误
“无法确定类型的复合主键排序 'Northwind.Order_Detail'。使用 ColumnAttribute 或 HasKey 方法 指定复合主键的顺序。”
但如果我也考虑 Order_details 和其他表,以及 OrderDetails 表的 HasKey,它工作得很好。
我的问题是,是否不可能使用几个表(此中单独的 Employee 表)案例)使用
public partial class NorthwindEntities : DbContext
{
public NorthwindEntities()
: base("Northwind")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
SetupModels(modelBuilder);
}
public DbSet<Employee> Employees { get; set; }
}
Anand 。
I could not work with employee table of Northwind database alone.
below code throws error as
"Unable to determine composite primary key ordering for type
'Northwind.Order_Detail'. Use the ColumnAttribute or the HasKey method
to specify an order for composite primary keys."
but it works fine, if I consider Order_details and other tables as well. and HasKey for OrderDetails table.
My Question is, is it not possible to work with few tables (Employee table alone in this case) using EF.
public partial class NorthwindEntities : DbContext
{
public NorthwindEntities()
: base("Northwind")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
SetupModels(modelBuilder);
}
public DbSet<Employee> Employees { get; set; }
}
Anand
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
主表具有到订单、订单详细信息表的导航属性。这会导致此错误。删除员工表中的导航属性后,它工作正常。
Master table has navigation property to Order , Order details tables. that causes this error. after removing navigation properties in Employee table, it works fine.