Should I be using all tables in the Entity Framework model?

I am creating an Entity Framework Model for a subset of Microsoft's Pubs database. I am only interested in publishers and books, not publishers and employees, but there is a foreign key constraint between the publishers and emoloyees tables. When I remove the employee entity from my model, the model will not be validated due to a foreign key constraint.

How do I create a model for a subset of a database when that subset is linked to other tabs with foreign key constraints?

Since this is for demonstration purposes, I removed the offending tables and constraints from the database, but it didn't work.

0


source to share


2 answers


The correct way to do this is to expose foreign key columns as scalar properties. There is a full explanation and downloadable sample code available in this blog post. You may find the rest of the post interesting too.



0


source


You can create views of the relevant data and link your model to that. I'm not a database expert, and the DBA I previously worked with recommended this approach because she said the view on the database server is less intensive.



Prior to 3.5 SP1, we built a DAL on top of LINQ to SQL (no DBML mappings, but that's another story) that mapped all domain objects to stored procedures or views. As such, the DBA was happy with calls that follow a more complex execution plan, and can also encapsulate database logic outside of the codebase.

0


source







All Articles