无法使用MySql Code First配置Entity Framework 5中的关联。

时间:2020-12-06 06:53:54

Doing this same example: http://weblogs.asp.net/manavi/archive/2011/04/24/associations-in-ef-4-1-code-first-part-4-table-splitting.aspx

做同样的例子: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();
}
}

Works perfectly fine in Microsoft SQL. but when executing on MySQL it creates the tables and somewhere in the generation (i think when applying the FK's) it's throws a :

在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

Im using connector 6.6.5 and Entity Framework 5.

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

Is this a problem with connector? With approach? Should I add some MySql configuration to support this? Thanks in advance.

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

1 个解决方案

#1


0  

Problem was because using Order as a Table Name and in the SQL sentence there's one place where it doesn't use ´order´.

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

Changed table name to SalesOrder and everything started to work flawlessly again.

将表名更改为SalesOrder,一切都开始完美无缺。

#1


0  

Problem was because using Order as a Table Name and in the SQL sentence there's one place where it doesn't use ´order´.

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

Changed table name to SalesOrder and everything started to work flawlessly again.

将表名更改为SalesOrder,一切都开始完美无缺。