Entity Framework 4 Import Function Does Not Work

I am using Entity Framework 4 with a POCO code generator. I have a stored procedure that executes an INSERT and returns @@ IDENTITY of an inserted record. I am trying to import a stored procedure as a function into my .edmx file, but I am having problems using it.

In the model browser, I can see the stored procedure in the database hierarchy, and then right-click and select "Import Functions ...". I tried using "No" as the return type, as well as Int32 (even if it says "Collection .."). The function is displayed in the Import Objects section, but even after saving and compiling, I cannot find the function anywhere in the ObjectContext. I tried deleting it and re-importing the stored procedure several times without success.

NOTE. I have another stored procedure that does a direct SELECT, and it is imported correctly and displayed in the ObjectContext code.

Am I doing something wrong?

+5
source share
2

, " " "" " " Visual Studio, . ( , , .)

sproc (, return @@identity) , " " . . , sproc.

, :

  • select (, @@identity Identity), Int32 " " .

  • , insert , 1.

  • Entity SQL . : .

, .

+5

POCO .Context.tt 111

if (edmFunction.ReturnParameter == null)
{
    continue;
}
string returnTypeElement = code.Escape(ef.GetElementType(edmFunction.ReturnParameter.TypeUsage));

, , 'none', .

.Context.tt ,

string returnTypeElement = @"";
if (edmFunction.ReturnParameter == null)
{
    returnTypeElement = @"void";
} else {
    returnTypeElement = code.Escape(ef.GetElementType(edmFunction.ReturnParameter.TypeUsage));
}

( 118)

<#
    if(returnTypeElement != "void"){
#>
    <#=Accessibility.ForMethod(edmFunction)#> ObjectResult<<#=returnTypeElement#>>   <#=code.Escape(edmFunction)#>(<#=paramList#>)
<#  
    } else {
#>
    <#=Accessibility.ForMethod(edmFunction)#> <#=returnTypeElement#> <#=code.Escape(edmFunction)#>(<#=paramList#>)
<#  
    } 
#>

return ( 142)

<#
    if(returnTypeElement != "void"){
#>
        return base.ExecuteFunction<<#=returnTypeElement#>>("<#=edmFunction.Name#>"<#=code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()))#>);
<#  
    } else {
#>
        base.ExecuteFunction("<#=edmFunction.Name#>"<#=code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()))#>);
<#  
    } 
#>  

( !), , import , , .Context.cs , , Intellisense.

+5

All Articles