TWilly
TWilly

Reputation: 4943

Add relationship from sql server "view" to table

I have an Sql Server View that returns a combination of a few different tables.

Is it possible to add in a relationship from the View to a foreign table so that Entity Framework could pick up on the relationship and add in foreign key constraint?

Upvotes: 0

Views: 273

Answers (2)

user743382
user743382

Reputation:

Is it possible to add in a relationship from the View to a foreign table

No.

so that Entity Framework could pick up on the relationship and add in foreign key constraint?

Entity Framework does not require a relationship to be backed by a foreign key constraint in the database. Even though you cannot add a foreign key constraint on a view in the database, you can still map the relationship in Entity Framework the same way you would for a table. It just won't be detected automatically for you.

Upvotes: 1

Akansha
Akansha

Reputation: 209

It is not possible to reference a view in a foreign key.

Upvotes: 0

Related Questions