Must I use all tables in an Entity Framework model?

I am building an Entity Framework model for a subset of the Pubs database from microsoft. I am only interested and publishers and books, not publishers and employees, but there is a foreign key constraint between the publishers and emoloyees tables. When I remove the employees entity from my model, the model won't validate because of the foreign key constraint.

How do I create a model for a subset of a database when that subset links to other tabes with foreign key constraints?

Because this is for a demo, I deleted the offending tables and constraints from the database, but this won't work in production.


The correct way to do this is by exposing the foreign key columns as scalar properties. There is a complete explanation, and downloadable sample code, in this blog post. You might find the rest of the post interesting, as well.

You could create views of the pertinent data and bind your model to that. I am not a database expert, but a DBA that I formerly worked with recommended this approach because she said that the view is less intensive on the database server to begin with.

Prior to the release of 3.5 SP1, we built a DAL on top of LINQ to SQL (without DBML mappings, but that is another story) that mapped all of the domain objects to either stored procedures or views. That way, the DBA was happy about the calls following a more set execution plan, as well as being able to encapsulate the database logic outside of the codebase.

Need Your Help

Parallel Compacting Collector algorithm

java algorithm garbage-collection jvm-hotspot

I have two questions. And one of them will be ragarding the topic:)

drawInRect does not read / preserve UIImageView transform

ios uiimageview cgaffinetransform drawinrect

I encountered a problem when I pinch, pan or rotate a UIImageview in drawInRect, the transform is not being preserved.