Showing posts with label ASP.NET MVC. Show all posts
Showing posts with label ASP.NET MVC. Show all posts

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.

Read More...

Unable to update the EntitySet Table because it has a DefiningQuery and no InsertFunction element exists in the ModificationFunctionMapping element to support the current operation

ASP.NET MVC is the technology released from Microsoft long time back. But I didn’t get time to dig into it and research on it. Now, I need to learn it as my next project is in ASP.NET MVC. So, I thought to give a try and want to show all records in a table and insert a new record in a table. On the way, The above is the exception which blocked me to go proceed. I didn’t do any mistake and always the above exception come into picture when I try to create a new record in table.
So, frustrated and started research on the error and debugging. After a long research found the issue in the Entity framework. The whole thing is only because I forgot to add primary key to the table in the database. Once I added the primary key and reconstructed the edmx file with new changes, All works fine and record added to table in database. So, what is happening inside is, entity framework is looking for a key in each and every table [Primary key]. So, don’t forget to add a primary key to each and every table which you want to use in entity framework file [.edmx]. Otherwise you always see this exception when you try to insert or update a record.
"Unable to update the EntitySet 'Table' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation."
Is this helpful? Follow me if you want to learn ASP.NET MVC framework. I started learning and will place all my experiences and problems I face in my blog. So, keep an eye on my blog for more updates. Read More...
Related Posts with Thumbnails
GiF Pictures, Images and Photos