Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foreign key must be mapped to some AssociationSet or EntitySets participating in a foreign key association on the conceptual side

I am trying to use a one to one (master, detail) relationship in Entity Framework, however, I get this error:

Problem in mapping fragments starting at lines 254, 443:Foreign key constraint 'options_Advanced_FK00' from table options_Advanced (ProductID) to table products (catalogid):: Insufficient mapping: Foreign key must be mapped to some AssociationSet or EntitySets participating in a foreign key association on the conceptual side

Here is the association in the designer:

enter image description here

It says product --> 0..1 options_Advanced

I used model-first and not code first. My Options Advanced table has one product associated with each record

Products

  • ID
  • CatalogID
  • Name

Options_Advanced

  • ID
  • ProductID
  • Name
like image 607
Joseph Anderson Avatar asked Jun 20 '13 02:06

Joseph Anderson


People also ask

What are the requirements for a foreign key?

Creating a foreign key constraint requires the REFERENCES privilege on the parent table. Corresponding columns in the foreign key and the referenced key must have similar data types. The size and sign of fixed precision types such as INTEGER and DECIMAL must be the same. The length of string types need not be the same.

What is the purpose of a foreign key and where it is placed?

Foreign keys link data in one table to the data in another table. A foreign key column in a table points to a column with unique values in another table (often the primary key column) to create a way of cross-referencing the two tables.

What are foreign keys used for in relational database systems?

A foreign key is a column or group of columns in a relational database table that provides a link between data in two tables. It acts as a cross-reference between tables because it references the primary key of another table, thereby establishing a link between them.

What is foreign key association?

Foreign Key Association is where you have a foreign key property in your model in addition to the corresponding Navigation Property.


1 Answers

I came accross this when searching for a solution to the same issue in a system I was working on.

I encountered this in VS2010 and it seems to happen when you are generating the model from the database as I was and you don;t include the objects at the same time. i.e including one table and not the other.

I got around it at this point by deleting the model and then recreating the entire model and including every table in the model that I thought I might need.

Now what happens when you add a new table I am not certain as I have not had to do this yet as I am working with an old application that we wish to convert

like image 96
Rick Avatar answered Oct 14 '22 02:10

Rick