Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Get Entity Framework To Update Complex Types?

I'm using the Entity Framework (EF) to create a complex type from a stored procedure. Recently, the stored procedure changed (more return values were added. I would like to update the complex type that maps to this stored procedure. Is this possible and if so, how? I am currently deleting my function import and complex type each time a stored procedure changes, which is most likely not the best approach.

like image 426
Halcyon Avatar asked May 12 '11 18:05

Halcyon


People also ask

How do I add a complex type to Entity Framework?

On the designer surface, select one or more properties (excluding navigation properties) of an entity, then right-click and select Refactor -> Move to New Complex Type. A new complex type with the selected properties is added to the Model Browser. The complex type is given a default name.

How do I update items in Entity Framework?

Update Objects in Entity Framework 4.0First retrieve an instance of the entity from the EntitySet<T> (in our case ObjectSet<Customer>), then edit the properties of the Entity and finally call SaveChanges() on the context.

How do I update entity framework sp?

Go to "Model Browser" > "Function Imports" > find the desired stored procedure class > right click and click on "Edit" In "Edit Function Import" form, in "Returns a Collection Of" section, click on "Update" button. Click "OK" to finish the refresh.


1 Answers

I found another way of doing this without deleting the complex type. You can update your Complex Type and Visual Studio will add any changed columns. Here's how:

  1. Open your .edmx file and go to the model browser.
  2. If your stored proc changed, right-click on any white area in the model browser and select Update Model From Database, click "Finish". This will refresh your stored procedure.
  3. Now drill down into XModel.edmx > XModel > EntityContainer:XEntities > Function Imports (X is your entity name) and right-click the one that you need to update. Select Edit.
  4. Click "Get Column Information". Now, next to the Complex Type radio button, there is a Update button. Press this to update your complex type and then press the OK button.

That should do it!

like image 98
Halcyon Avatar answered Sep 23 '22 19:09

Halcyon