开发者

Can I implement foreign keys in Entity Framework 4 at the entity layer?

开发者 https://www.devze.com 2023-01-20 16:05 出处:网络
I have a sizable legacy MS SQL da开发者_运维百科tabase where foreign key relationships were never implemented.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消