Adding stored procedures complex types in Entity Framework
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
:
(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:
(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:
Mapping Stored Procedures to Complex Types in EF
Unfortunately, you cannot do what you're trying to do. If you have two separate stored procedures which returns two distinct sets of data (even if one is a superset of the other), you will need to use two separate complex types to map those stored procedures to.
As you've seen yourself: when you try to "re-use" the complex type for the second stored procedure (which returns fewer columns), you will run into an error something like this:
System.Data.EntityCommandExecutionException was unhandled
The data reader is incompatible with the specified 'xxxxxxx'. A member of the type, 'ABC', does not have a corresponding column in the data reader with the same name.
Source=System.Data.Entity
and your second call will never work. I don't see how you could solve this - other than using two distinct, separate complex types that exactly match the output "shape" of your stored procedures.
Creating entity framework complex types of store procedures with oracle
I found the solution on following link.
https://www.oracle.com/webfolder/technetwork/tutorials/obe/db/dotnet/2015/entityframework_linq_modelfirst/Entity%20Framework%20LINQ%20and%20Model%20First.html
How Do I Get Entity Framework To Update Complex Types?
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:
- Open your .edmx file and go to the model browser.
- 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.
- 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.
- 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!
Entity Framework database first does not generated all complex types for stored procedures
for Complex type i always use simple =
List<Complex_Type_Class> _lsComplexReturn =EntityObject.ExecuteStoreQuery<Complex_Type_Class>(@"storeProcedureName;");
and class is like
public class Complex_Type_Class
{
//all returns value's get set
}
Related Topics
How to Pinvoke to Getwindowlongptr and Setwindowlongptr on 32-Bit Platforms
Async Network Operations Never Finish
Display a Image in a Console Application
Datetime Format to SQL Format Using C#
How to Get Urls of Open Pages from Chrome and Firefox
How to Use C# to Sanitize Input on an HTML Page
Get Thumbnail Image of Video File in C#
Enable Options Header for Cors on .Net Core Web API
The Calling Thread Must Be Sta, Because Many UI Components Require This in Wpf
How to Access Openxml Content by Page Number
How to Read an Outlook (2003/2007) Pst File in C#
What Are Best Practices for Using Smtpclient, Sendasync and Dispose Under .Net 4.0
How to Make Method Call Another One in Classes
How to Add a Custom Routed Command in Wpf