How to use DbContext.Database.SqlQuery(sql, params) with stored procedure? EF Code First CTP5

后端 未结 10 1937
梦谈多话
梦谈多话 2020-11-22 16:53

I have a stored procedure that has three parameters and I\'ve been trying to use the following to return the results:

context.Database.SqlQuery

        
10条回答
  •  甜味超标
    2020-11-22 17:36

    I did mine with EF 6.x like this:

    using(var db = new ProFormDbContext())
                {
                    var Action = 1; 
                    var xNTID = "A239333";
    
                    var userPlan = db.Database.SqlQuery(
                    "AD.usp_UserPlanInfo @Action, @NTID", //, @HPID",
                    new SqlParameter("Action", Action),
                    new SqlParameter("NTID", xNTID)).ToList();
    
    
                }
    

    Don't double up on sqlparameter some people get burned doing this to their variable

    var Action = new SqlParameter("@Action", 1);  // Don't do this, as it is set below already.
    

提交回复
热议问题