views:

29

answers:

2

I have a sizable legacy MS SQL database where foreign key relationships were never implemented.

Is it possible to implement "logical" foreign keys between entities in Entity Framework 4 without there being actual foreign key relationships present in the database?

+2  A: 

Yes. In the toolbox, there is "Associations". Just drag from one entity to the other and it will create a "foreign key" for you. Click this association, and go to Properties to change the name and the relationship (1 to Many, Many to Many). Then choose "Mapping Details" to map the columns for this association.

Martin
+2  A: 

Even if it is possible, it is is not the optimal choice. Implement them in the database where they belong. If that means you have to clean up bad data first, well that's the price of designing wrong from the beginning. You need these things at the database level because not everything that affects data in a database goes through the entity framework and it is a bad thing to allow data integrity problems to come in from any source.

HLGEM
Oh I agree totally. There are already certain "integrity" problems. But it'd take me a month or so to put right, which I do plan to do. But I'd like to freeze out and bin the umpteen different data access libraries that have been cobbled together over the years and standardise on EF sooner than later.
Kev
Yes but even if you standardize on it, there will be SSIS imports or update queries run through the query window to fix an emergency data issue that will not go through the framework. The fix must be at the database level to actually be a fix.
HLGEM