I have a sizable legacy MS SQL da开发者_运维百科tabase 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?
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.
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.
精彩评论