EF Codefirst 无法处理 Northwind 数据库的部分表

发布于 2024-11-26 08:21:52 字数 684 浏览 6 评论 0原文

我无法单独使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木森分化 2024-12-03 08:21:52

主表具有到订单、订单详细信息表的导航属性。这会导致此错误。删除员工表中的导航属性后,它工作正常。

Master table has navigation property to Order , Order details tables. that causes this error. after removing navigation properties in Employee table, it works fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文