Header

Friday, October 7, 2011

Entity Framework Tidbit 2

I'll be discussing about custom associations in entity framework. You will need this when you want to create a link between two tables which are related but no relation constraints defined. Usually, this happens for tables whose relationship to one another is not really that significant to the system. The relationship is only established on a per need basis only. To create this relationships in entity framework, you need to add a custom association between the tables.  I consider it custom since, when you add tables in the entity model which have relation constraints, the association between the tables is automatically created. Here's the steps on how to do this:

1. Right click at the table and select new association.


2. Uncheck the "Add foreign key properties to.."


3. Click on the line created linking the two tables you have associated and go to properties. Then, set the referential constraints for the two tables.








After that, you have created a custom association between two tables! :)

No comments:

Post a Comment