Tuesday, October 27, 2009

How to drag and drop entities from server explorer to EDMX file Entity Framework?

I know for adding the tables/entities to the EDMX file from database, everyone should do this. You will open server explorer, connect to database, expand to tables and select tables you want to add and tried to drag and drop them to EDMX file. But you never succeeded… Am I right? So, Everyone thinks like this by default because we are well used the LINQ files these days. We have the drag and drop support in it. But in Entity framework we don’t have that option as far as I know. Then how to add new database objects to the edmx file? There are two ways one is manual and another is tool.

  • Manual: Open the edmx file in the xml editor to see the code and edit the changes as you needed. Which is complex and won’t yield good results.
  • Tool: We have an option from the diagram file edmx designer to update the model through designer. Which is very simple and we can add/remove objects as we need.

Note: For entity framework there is a special explorer in visual studio 2008 which helps us to see only entity framework related objects which is called "Model Browser". Which is really very simple to use and helps a lot if your DB is big.

image

How to add entities/database objects to EDMX file?

  • Open the EDMX file in design mode.
  • Right click on the designer surface. You have lot of options and among them choose the option "Update Model from Database.." as shown below.
  • image
  • Now, you will see the usual screen which has all the database objects in new window which you have seen while creating EDMX file.
  • image
  • That's it!!! This way you can add/remove/edit database objects in an EDMX file. Usually the drag and drop is the good user experience as it in is in Linq to SQL file. Hope Microsoft include this option in upcoming releases.

I think, you knew about how to add or update db objects in EDMX file now. Love to hear comments.

3 comments:

  1. I was triying/searching for 5 minutes draging from the server explorer :D Then I decided to search in google.

    ;)

    ReplyDelete
  2. Thanks a lot, makes you wonder why VS2010 couldn't give me the same guidance!

    ReplyDelete
  3. I did used this while dragging tables from the server explorer to edmx, I was getting some sign while dropping items and due to that I was not able to drop items correctly.

    ReplyDelete