Many-to-many relationships

Oct 14, 2010 at 4:52 PM
Edited Oct 14, 2010 at 4:53 PM

I've added support for many-to-many relationships to the T4 template. If you need this feature right now and can't wait until the next release (1.0.1), you can download the source code from the repository and copy-paste T4 template to your project. Don't forget to edit path to the edmx file.

Problem description: 

When using join table which contains only primary keys from two tables, entity framework designer does not show the join table on the designer area. For example, we have two tables: Employees (EmpID, EmpName),  Locations (LocationID, LocationName), and one join table: Employees_Locations (EmpID, LocationID). If we create EF model and import all the tables, only two entities will be created: Employees and Locations. Each entity will contain navigation property (eg. Employees->Locations) which contains list of related objects. If you then add a new Location to the Employees->Locations list, new location will be inserted to the Locations table, but also a new database record will be inserted to the join (Locations_Employees) table. This functionality is now supported when using CslaExtension.

If you want to avoid this EF behaviour, you can add another column to the join table (eg. InsertTime). In that case all 3 entities will be created in the model and you can use them normally with CslaExtension.