Stored procedure returns int instead of result set

后端 未结 17 1958
说谎
说谎 2020-12-03 13:02

I have a stored procedure that contains dynamic select. Something like this:

ALTER PROCEDURE [dbo].[usp_GetTestRecords] 
    --@p1 int = 0, 
    --@p2 int =          


        
相关标签:
17条回答
  • 2020-12-03 13:57

    Well I had this issue as well but after hours of online searching none of above methods helped. Finally I got to know that It will happen if your store procedure is getting some parameters as null and which generate any error in query execution. Entity Framework will generate method for store procedure by defining the complex entity model. Due to that null value your store procedure will return and int value.

    Please check your store procedure either its providing empty result set with null values. It will fix your problem. Hopefully.

    0 讨论(0)
  • 2020-12-03 13:59

    I get this when I have a stored procedure that includes an "exec" call into a temporary table, such as:

    insert into #codes (Code, ActionCodes, Description)
    exec TreatmentCodes_sps 0
    

    It appears that Entity Framework gets confused as to what should be returned by the procedure. The solution I've come across is to add this at the top of the sproc:

    SET FMTONLY OFF
    

    After this, all is well.

    0 讨论(0)
  • 2020-12-03 14:02

    I got the same problem, and found solution here

    1. Move to your .edmx
    2. At Model Browser Window/Function Imports find your procedure then double click it
    3. Change the return type to you want
    4. Save .edmx and check the return type again.

    It should be what you need now.

    0 讨论(0)
  • 2020-12-03 14:04

    If SQL Authentication is in place, verify that the user credential that is being used to connect Entity Framework to the database has the proper rights to read from CUSTOMERS table.

    When Entity Framework uses SQL Authentication to map complex objects (i.e stored procedures that SELECTs more than one column), if any of the tables from within such stored procedure don't have set up the Read permission, the mapping will result in returning INT instead of the desired Result set.

    0 讨论(0)
  • 2020-12-03 14:07

    During import

    SET FMTONLY ON can be used for taking the sp schema.

    If you change the sp and want to update the new one, you should delete the old defined function from edmx file (from xml), because although deleting sp from model browser, it is not deleted in edmx. For example;

        <FunctionImport Name="GetInvoiceByNumber"     ReturnType="Collection(Model.Invoice_Result)">
           <Parameter Name="InvoiceNumber" Mode="In" Type="Int32" />
        </FunctionImport>
    

    I had the same problem, and when I delete the FuctionImport tag of corresponding sp totally, the model updated right. You can find the tag by searching the function name from visual studio.

    0 讨论(0)
提交回复
热议问题