How does ADO.NET Entity Model Assign Primary Keys?

If you’ve used the ADO.NET Entity Data Model to generate some models from your database schemas you’ll have noticed that sometimes ADO.NET assigns primary keys that does not necessarily correlate with your database schema. This is specially true if you are pulling from a view that has several joins. For instance, notice in this model the Term, the SrsNumber and the CatalogNumber is marked as the primary keys (Course happens to be a View in this case):

course

But in reality, the actual table the view pulls from only has Term and SrsNumber marked as the primary keys. So what’s going on? Turns out the ADO.NET Entity Data Model assigns primary keys to all non-null columns.

If you have the freedom to correct this in the database schema then that’s one solution to mark columns nullable otherwise you’ll have to manually adjust the CSDL (Conceptual Schema Definition Language) file manually. More on that tomorrow.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Live
  • StumbleUpon


Leave a Reply