EF UpdateModel and naming conflicts

When you use the UpdateModel feature of the Entity Framework design tools, the process relies on matching up existing entity names to table names, more specifically name of objects in the CSDL with names of objects in the database.

IF you have selected objects to add and nothing with that name already exists, it will add a new entity in the model, otherwise, it will use the existing entity.

There are changes coming to how this works detailed in this blog post by Noam Ben-Ami.

But I got bit by something that I overlooked which took hours to pinpoint the cause of the problem, so I wanted to share it.

I had created a model from scratch that was a simple, generic commerce app (see image below). I created entities for Customer, Order, LineItem, Address and Product with some properties, entity keys and associations.

Then I linked it up to  a database using UpdateModel to create the SSDL for me but nothing happened.

It took a lot of experimenting before I realized that the problem was that I was trying to add in a CustomerAddress table but I had an association named CustomerAddress. If that had been an entity, it wouldn’t have posed a problem. But the wizard did not know how to handle the fact that it was an association and just completely gave up the ghost.

The only problem I see here is that some indication of the conflict would have helped me figure out what was wrong a little sooner, though I don’t expect the wizard to overcome the conflict on its own. I did make a note of this in the forums. However, I am putting the info here for posterity in case it’s too late to change the wizard for RTM and somebody else gets stuck on the same problem.

  Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!  

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.