3
votes

I have a Custom POCO (Already existing und used in my project).

public class MyPoco()
{
     public string MyPocoName {get; set;}
     public string MyPocoParentName {get; set;}
}

I have also a stored procedures that returns a list of (MyPocoName,MyPocoParentName) values.

I couldn't set MyPoco as the return type of this procedure in the Function import wizard.

I don't want to create a new custom type that have the same proporties as MyPoco.

Is there any way that could specify the return type of the stored procedure to be MyPoco.

Thanks.

2

2 Answers

8
votes

Yes there is a way but you must not use function import (adding stored procedures to your model doesn't make sense in this case). Use:

var data = objectContext.ExecuteStoreQuery<MyPoco>("spName", SqlParams);

to call you stored procedure.

1
votes

I had to add the param list after the spName:

        var results =
            this.Context.Database.SqlQuery<MyPoco>(
                "spName @param1, @param2, @param3",
                new SqlParameter("@param1", var1), 
                new SqlParameter("@param2", var2),
                new SqlParameter("@param3", var3));