Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I working on an MVC product using Database first entity framework approach, I added a few stored procedure to the EDM, but some are returning string instead of the model type. I have deleted the model.edmx, removed the connection string from the web.config file and re- added model1.edmx file to the project, yet, some still have string as return type, I have also created a viewmodel class and use it in place of the string, yet no luck. I want to be able to add procedure to return type of the model.

Stored Procedure in Model1.Context class:

C#
public virtual ObjectResult<string> PreLoadWorkflowType()
{            
    return((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<string>("PreLoadWorkflowType");
}


I want the generated stored procedure to look like this instead:

public virtual ObjectResult<PreLoadWorkflowType> PreLoadWorkflowType()
{               return((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<PreLoadWorkflowType>("PreLoadWorkflowType");
} 



Stored Procedure:

SQL
USE [databsename]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[PreLoadWorkflowType]
AS
BEGIN
SET NOCOUNT ON;
select distinct workflow_type  AS WorkflowType from V_ui_View  where 
workflow_type is not null 
END


I have been adding stored procedure to the EDM file all the while, i have not experience this before, I will appreciate assistance from anyone who had experienced and resolved this.

What I have tried:

public virtual ObjectResult<PreLoadWorkflowTypeViewModel> PreLoadWorkflowType()
{               return((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<PreLoadWorkflowTypeViewModel>("PreLoadWorkflowType");
}
Posted
Updated 30-Jan-18 1:30am

1 solution

In the model browser select your SP and in the properties window click "Return Type" then click the ellipses button to open the "Edit Function Import" dialog.

In the "Returns a collection of" if you want the SP to return instances of an existing entity then select Entities and the relevant one. If the data doesn't match an existing entity then select "Complex", click "Get Column Information", then click "Create New Complex Type" and it'll create a class for you with the relevant properties and amend the code so it now returns ObjectResult<YourComplexType>
 
Share this answer
 
Comments
Uwakpeter 30-Jan-18 9:58am    
Thanks you sir, i really appreciate, it works

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900