Stored Procedure return -1 for all cases in entity framework

后端 未结 3 1318
无人共我
无人共我 2020-12-16 12:08
CREATE PROC spIsValidUser
     @UserName varchar(50),
     @Password varchar(50) 
AS
    IF  Exists(SELECT * FROM Users where UserName=@UserName and Password=@Passwo         


        
3条回答
  •  粉色の甜心
    2020-12-16 12:57

    Have you imported your stored procedures in the EF model correctly? and are you setting correct return type to stored procedures??

    There are 4 possible return type that you can set to your procedures The possible return types are:

    1. none
    2. Scalars
    3. Complex
    4. Entities

    you need to set scalars return type.

    if you dont know how to set the return type, then here is the full tutorial http://www.binaryintellect.net/articles/30738a7c-5176-4333-aa83-98eab8548da5.aspx

    quick example.

    CREATE PROCEDURE CustOrderCount
        @CustomerID nchar(5)
    AS
    BEGIN
        SELECT COUNT(*) FROM ORDERS 
            WHERE CUSTOMERID=@CustomerID;
    END
    
    
    NorthwindEntities db = new NorthwindEntities();
    var count = db.CustOrderCount("ALFKI");
    int ordercount = count.SingleOrDefault().Value;
    

    this will return int order count.

提交回复
热议问题