【问题标题】:Can't configurate associations in Entity Framework 5 with MySql Code First.无法在 Entity Framework 5 中使用 MySql Code First 配置关联。
【发布时间】:2013-03-13 17:35:48
【问题描述】:

做同样的例子: http://weblogs.asp.net/manavi/archive/2011/04/24/associations-in-ef-4-1-code-first-part-4-table-splitting.aspx

public class Order {
    public int OrderId {get;set;}
    public virtual OrderBilling Billing { get; set; }
}

public class OrderBilling {
    public int OrderBillingId { get; set; }
    public string Name { get; set; }
}

public DbSet<Order> Orders { get; set; }
public DbSet<OrderBilling> OrderBilling { get; set; }

public class OrderConfiguration : EntityTypeConfiguration<Order> {
    public OrderConfiguration() {
    HasRequired(o => o.Billing)
        .WithRequiredPrincipal();
}
}

在 Microsoft SQL 中运行良好。 但是在 MySQL 上执行时,它会创建表并在一代中的某个地方(我认为在应用 FK 时)它会抛出一个:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Order (OrderId)
ON DELETE NO ACTION ON UPDATE NO ACTION' at line 3

我正在使用连接器 6.6.5 和实体框架 5。

这是连接器的问题吗?用方法?我应该添加一些 MySql 配置来支持这个吗?提前致谢。

【问题讨论】:

    标签: mysql ef-code-first entity-framework-5


    【解决方案1】:

    问题是因为使用 Order 作为表名,而在 SQL 语句中有一个地方没有使用“order”。

    将表名更改为 SalesOrder,一切又开始完美运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-11
      • 1970-01-01
      • 1970-01-01
      • 2014-05-08
      • 1970-01-01
      相关资源
      最近更新 更多