Add foreign keys relationship to Entity Framework Database first
I have a database in TSQL and I use ADO.NET Entity Framework from .NET 3.5 to create the matching entities.
In the database the relationships are not modeled, but in each table involved in a relationship there is a field representing the foreign key to another table's primary key.
For instance (assume a Product
can have just one category):
Product ( ProdId(PK), ProdName, CatId(FK))
Category (CatId(PK), CatName)
This way of course there is no referential integrity constraint.
In my application I generate the EF entities from the database and then I add the relationships and their mapping by hand. Everything goes smooth except for the one-to-many relationships.
The mapping specified for the many-to-many relationships (through association table) do not give any kind of error, those specified for the one-to-many
Error 3007: Problem in mapping fragments :Column(s) [foreign_key] are being mapped in both fragments to different conceptual side properties.
Now I checked the mapping , I changed cardinality and directions but still it does not work.
I read in the internet that I should remove the foreign keys but then, how can I map the values in the database? Is there any other solution?
Important: I cannot use .NET 4.0 I have to stuck with .NET 3.5
链接地址: http://www.djcxy.com/p/37474.html上一篇: 使用Entity Framework Fluent API进行一对一的可选关系
下一篇: 首先将外键关系添加到实体框架数据库