我正在使用代码设计我的数据库,我需要一点帮助。实体框架代码首先定义关系/键
我收到此错误:
Introducing FOREIGN KEY constraint 'SalesOrder_Invoices' on table 'Invoices' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint. See previous errors.
我想有以下关系/键:
--> = 1 to Many Relationship
- 客户 - > CustomerLocation
- CustomerLocation - > SalesOrder
- SalesOrder - >发票
- 的SalesRep - > SalesOrder
- PaymentTerm - >客户
- PaymentTerm - > SalesOrder
- PaymentTerm - >发票
我试图去界定按以下标准:
<ClassName><PrimaryKeyID>
例如:Customer
有ID
属性,所以在CustomerLocation
我定义了外键,像这样:
Public Property CustomerID AS Integer
所有我需要做的就是定义外键是否正确?我是否也必须为每个我定义的键拥有导航属性?
而且,我可以在一个对象的同一主键上没有多个外键吗?
更新
所以要定义一个关系,你用的ClassName.PrimaryKeyProperty
?或者你使用导航属性?或两者?困惑!!
更新2
因此,为了使你必须定义双方的关系的工作......我想。
Public Class Customer
Public Property ID AS Integer
Public Overrideable Property Locations AS ICollection(OF CustomerLocation)
End Class
Public Class CustomerLocation
Public Property ID AS Integer
Public Property CustomerID AS Integer
End Class
因此,要建立一个关系的工作,你必须定义双方?请参阅我上面的更新。 – Sam 2011-04-04 00:12:10
@Sam:不,你不需要双方的导航属性。 – 2011-04-04 06:16:15
我喜欢'OneToManyCascadeDeleteConvention'提示这个答案。 – batwad 2012-01-31 16:54:17