Reputation: 1
I have 2 project in my .net solution.each one has entity data model.how I can make an association between two entities one in the first project data model while the other in the second project data model in the same solution?
what if each data model mapped to different database?
Upvotes: 0
Views: 596
Reputation: 1845
It is impossible to have a database relation between two fields in separate databases, however, you can do this of course with server side logic in your application code. If you do, make sure you add a trigger to enforce referential integrity to make sure the relation can be made if it requires a field not to be null
Add Foreign Key relationship between two Databases
Create Trigger dbo.MyTableTrigger ON dbo.MyTable, After Insert, Update
As
Begin
If NOT Exists(select PK from OtherDB.dbo.TableName where PK in (Select FK from inserted) BEGIN
-- Handle the Referential Error Here
END
END
Upvotes: 0
Reputation: 553
As far as I know you can't achieve this within a reasonable solution.
Upvotes: 1