tympaniplayer
tympaniplayer

Reputation: 171

Entity Framework 5 not adding foreign key

I have two tables in a SQL Server 2012 Express database that are defined like this.

SampleTableOne ColumnName nvarchar(50) Primary Key Id int

SampleTableTwo Id int Primary Key ColumnName nvarchar(50)

When I add a foreign key using the following command

ALTER TABLE SampleTableOne
ADD FOREIGN KEY(Id) REFERENCES SampleTableTwo(Id)
ON DELETE CASCADE
ON UPDATE CASCADE
GO

However when I add the models into Entity Framework, it is not adding the foreign key. I have "Include Foreign Key Columns In The Model" selected. Is there a step I am missing?

EDIT:

I am aiming for a one to one relationship.

Upvotes: 0

Views: 888

Answers (1)

zandi
zandi

Reputation: 704

in the third part and sixth part of Associations in EF Code First saw the limitations of shared primary key association and argued that this type of association is relatively rare and in many schemas, a one-to-one and to Many-valued association is represented with a foreign key field and a unique constraint.

Upvotes: 1

Related Questions