Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I automatically Update Entity Framework Function Imports

I'm using entity framework to call my stored procedures. I'm going through the process using the function import wizard as to create function imports and complex types.

The problem I'm having is I would like to find a way to easily refresh all of my complex types.

When there are stored procedure change today, my process is to:

1.) Refresh stored procedures using the EF update wizard.

2.) Go to each function import in the model browser and click edit.

3.) Click the button to update complex type.

4.) Manually repeat this process for all 100+ of my function imports.

This update process is very well explained here: http://blogs.msdn.com/b/nihitk/archive/2010/04/23/ado-net-entity-designer-in-vs-2010-stored-procedure-return-type-shape-sensing.aspx

Does anyone know how this can be automated either via a command line or through some sort of macro. I don't need this to be part of a build process.

like image 279
DTig Avatar asked Jan 20 '12 00:01

DTig


People also ask

How do I import a function into entity Framework?

Update Model from Database –> Add –> Stored Procedure) 2) Right-click on your diagram and choose Add –> Function Import. Enter the name you want to use as the Entity function to retrieve the stored procedure. Select the stored procedure you want to associate with this Entity Function. Press Get Column Information.

How do I update entity framework complex type?

Refactor an Entity's Properties into New Complex TypeOn 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.

How do I add SP to EDMX?

Add stored procedure in EDM: As we added tables in the EDM, the same way you can add stored procedures in the EDM. If you want to add it in existing EDM the right click on designer and click on "Update model from database..". This will popup update wizard where you can select stored procedures and add it.


1 Answers

Check out the EdmGen command-line tool that comes with Entity Framework. Figure out what command line switches you need to generate an EDMX that contains your function imports (and quite likely a lot of other stuff).

Then write a small command-line program that uses XDocument and LINQ to XML to read the XML elements you want out of the generated EDMX and then uses the same technique to overwrite the ones in your real EDMX.

If you want this process to be part of the build (it will slow things down though) add these two commands to your project's Pre-build event command line settings in project properties.

Other developers and the build server would also need a compiled version of your new merging command checked-in somewhere to call.

like image 130
DamienG Avatar answered Nov 03 '22 21:11

DamienG