In the Entity Framework, how do you construct a connection between a table and a view?

entity-framework sql-server-2008

Question

On the basis of a SQL Server 2008 database, the Visual Studio 2008 wizard created an Entity Framework model for me.

The model contains a view that logically connects to another table via a join table in a many-to-many connection (enforced in the database by an insert/update trigger). The view and the tables are both a part of the model, but the view does not have the connection with the join table since a view cannot have a foreign key constraint.

Is it feasible to build a connection between the join table and the view in the Entity Framework model?

Thank you for any assistance.

1
9
2/2/2010 2:17:18 PM

Accepted Answer

The GUI designer won't be able to infer this for you, but you can do it.

The first action that must be taken is setup the view properly. You must provide the main key since it cannot be deduced by the designer.

Now that there is a blank spot in the designer, you may right-click there and choose to create an association. Set the cardinality appropriately and define the relationship between your view and table.

The FK fields must be deleted from the client schema in EF 1 by selecting them in the designer and clicking the delete button. This is due to the fact that in EF 1, a field cannot be mapped to both a scalar property and an association. If you utilize FK associations in EF 4, you may maintain the FK fields, or you can use independent associations, which operate more like EF 1.

17
2/2/2010 2:58:27 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow