locked
Using a Stored procedure in entity framework. RRS feed

  • Question

  • I'm trying to use a stored procedure in the entity framework. I had the model created initially without the stored proc. I then went into Update Model from Database and selected the stored procedure I wanted and then added it through the function import. Now I can see the function in the model browser under Function Imports but when I try to call it on the object context I get the error saying 'xxModel' does not contain a definition for 'xxfunction'. Any idea what I could be doing wrong?

    Friday, February 13, 2009 6:23 PM

Answers

  • When you use function import and the return type from sproc/function is not of type Entity then it doesn't get code-gened on Object Context. Therefore you cannot call ObjectContext.xxFunction. The only way to call this function is by explicitly creating entity command and calling the store function directly.

    Next version of Entity Framework will support function import with all return types on object context. Sorry for inconvenience.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Proposed as answer by Asad - MSFT Tuesday, February 17, 2009 10:31 PM
    • Marked as answer by sitty Wednesday, February 18, 2009 3:17 PM
    Tuesday, February 17, 2009 10:30 PM

All replies

  • You need to import the function into your conceptual model.  Find the function under the "stored procedures" tab in the model browser, right-click the function, and choose "add function import". 

    If you did this, please post a copy of your EDMX file (or a slimmed down copy of your EDMX that reproduces the problem) and I'll take a look.

    Thanks,

    Mike Kaufman
    Microsoft Corp.
    This posting is provided "AS IS" with no warranties, and confers no rights
    Friday, February 13, 2009 10:01 PM
  • Here are the tag definitions I found for the stored proc in edmx file 


     
    <Function Name="p_DeleteDealFacts" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo"
              <Parameter Name="DealID" Type="int" Mode="In" /> 
            </Function> 
     
    <Function Name="p_DeleteDealFacts" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo"
     

    Does this help? If you want the whole file I can email it to you.

    Thanks.
    Tuesday, February 17, 2009 8:52 PM
  • When you use function import and the return type from sproc/function is not of type Entity then it doesn't get code-gened on Object Context. Therefore you cannot call ObjectContext.xxFunction. The only way to call this function is by explicitly creating entity command and calling the store function directly.

    Next version of Entity Framework will support function import with all return types on object context. Sorry for inconvenience.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Proposed as answer by Asad - MSFT Tuesday, February 17, 2009 10:31 PM
    • Marked as answer by sitty Wednesday, February 18, 2009 3:17 PM
    Tuesday, February 17, 2009 10:30 PM