Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding stored procedures complex types in Entity Framework

I am trying to use a stored procedure in Entity Framework that returns nothing.

I did the following:

  1. Added a function (right click on stored procedure -> add -> function import-> Complex Type -> Get column information -> create New Complex-Type)

  2. My function name: summarySP_Result. After building the project the entity class is not generated in Generated_code (BusinessAccount.web.g.cs)

But entity classes for tables and views are all created but nor for stored procedure.

Can anybody give the idea why it is not generated entity class in BusinessAccount.web.g.cs?

Update :

Let me confirm ReturnDataFromTemTable_result entity class created in your XXXXXX.web.g.cs class.

Like :

[DataContract(Namespace="http://schemas.datacontract.org/2004/07/BizFramework.Web.Model")] public sealed partial class ReturnDataFromTemTable_Result : Entity {    -------------------  } 
like image 768
Kavitha Avatar asked Oct 11 '12 06:10

Kavitha


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 Entity Framework complex type?

Select Edit. 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.

Can we use stored procedure in Entity Framework?

The Entity Framework has the capability of importing a Stored Procedure as a function. We can also map the result of the function back to any entity type or complex type.


2 Answers

OK - here's the step-by-step way of doing this:

(1) add your stored procedure to the EDMX file (when you first create it, or later on by using Update model from database and picking that stored procedure)

(2) once you have the stored procedure in your model - use the Model Browser to add a Function Import :

enter image description here

(3) the next dialog that pops up is vitally important - you need to (1) define that the stored procedure returns a collection of complex types, then you need to (2) get the column info from that stored procedure to know what columns it will return, then (3) you tell Visual Studio to generate a new complex type based on that column info:

enter image description here

(4) once you've done that - you should now see the stored procedure in your conceptual model section in the Model Browser, and the newly generated complex type should show up there, too:

enter image description here

like image 130
marc_s Avatar answered Oct 04 '22 14:10

marc_s


This is for Ross Brigoli

Try adding this line to the beginning of your stored procedure:

SET FMTONLY OFF You can remove this after you have finished importing.

Source:- Why can't Entity Framework see my Stored Procedure's column information?

like image 23
Sandeep Avatar answered Oct 04 '22 14:10

Sandeep