More Designer Improvements - Deleting Entities from the model and from the store schema

Previous "What's New in EF 4 Posts"

ef4

 

One of the big EDM Designer gotchas in the  VS200 SP1 tools happened when trying to delete entities from the model. It was an FAQ on the forums as well as in emails that a number of people sent to me directly. I thought I even blogged about it  but can't put my finger on the post.

 

Here's the problem in the current version. If you delete an entity from your model, it is removed from the CSDL portion of the metadata. But the original store representation in the SSDL portion of the data is not removed. Then if you decided to bring that entity back into the model using the Update Model wizard, that entity is not available to import. The reason is that the wizard looks at the database and looks to see what db objects are NOT represented in the SSDL. Since that object was not removed from SSDL it doesn't see a need to present it to you. As far as the wizard is concerned it is already there. The only workaround is to go into the raw XML and remove the entity and any references to it from the SSDL. Not fun for the XML-wary.

The EF tools team is well aware of this problem and thankfully fixed it in EF4. But they also added another neat feature.

Let's look first at the fix to the original problem so you can see the proof rather than just believing everything you read. Assuming that you trust me not to doctor up my screen shots.

Here's my model that I worked SOOOOO hard to create. ;-)

deleteentityA

If I delete the Customer entity, I get the following dialog.

deleteentityab

Now look at this carefully. If you are like me, you will assume it is just asking "are you sure? and click "Yes". But that's not the case at all.

The question is not about deleting the entity from the model. It's asking if you want to also remove the store schema metadata.

So let's say YES.

(If you say No, the entity will be deleted but the store schema will remain. You can Cancel to forget the whole thing and leave the entity in the model after all.)

deleteentityB

Of course, I could just hit Undo, but where's the fun in that? Here's the Update Wizard. It's displaying the Customer as an object that I can import into my model. As expected! That's what has been so confusing to people using VS2008. You would expect this to be there but it's not. Now in VS2010, it's there.

deleteentityC

And voila. My customer pops into the model and figures out its' associations and there you have it.

deleteentityD

Now here's another interesting feature. What if I had said NO to the question?

The customer gets deleted, but not the related entity in the  store schema.

Here I'm also showing the model browser. You can see that although the Customer is gone from the model, it is still listed in the Store schema.

deleteentityE

 

So when decide I want the customer in there after all and run the Update Wizard, I am not able to bring in the Customer. It's just not available (for the reason explained at the start of this post).

But there is another new feature in the Model Browser that helps resolve this. Unfortunately, I think many people will still not understand WHY the Customer is not available to be brought back in. Hopefully they'll read my blog post or remember the message in the dialog when they deleted the Customer.

The model browser now lets you easily delete Store schema objects. Right click on the Customer and delete it from there.

deleteentityF

You can't delete model objects this way, just store objects.

But be careful. You can delete store objects that are needed in your model. For example, my Order entity maps to the Orders table that is described in the Model.Store If I delete the Orders from the Store this way, I will break my model. The Order entity is no longer mapped to anything. There's no warning. Remember, this is a Beta and I did just point this out to the EF tools team so hopefully it will be a little better when this RTMs.

A few things on my Model Browser Wish List

I had a very specific lists of things I really was hoping to see. One of them was in an early beta of V1. If you hovered over an object in the model browser, it would show you the XML for that particular element. I loved that but it was something that the team thought was too confusing for most users. As they improve the designer, the hope is that most people will never need to use the XML anyway, so that's reasonable. Though I'd like to have an "advanced user view" I could switch on. Oh well. Another thing I had asked for that is not there for the same reason is the ability to right click on an object in the model browser and be able to navigate directly to that section of XML in the raw metadata file. Can't do that either.

#1 Jiri Cincura on 6.09.2009 at 5:29 PM

The option to navigate from object into the XML section of this object would be great.

#2 Julie on 6.09.2009 at 5:39 PM

Hey Jiri

Let the team know. THat will make two of us. :-)

#3 Jiri Cincura on 6.10.2009 at 5:51 AM

Do you have an item in connect.microsoft.com?