标签:
//create parameters to pass to the stored procedure
//First input Parameter
var param1 = new SqlParameter { ParameterName = "@paramName1",
SqlDbType = SqlDbType.Int, Direction = ParameterDirection.Input, Value = 1 };
//Second input parameter
var param2 = new SqlParameter { ParameterName = "@paramName2",
SqlDbType = SqlDbType.VarChar, Direction = ParameterDirection.Input, Value = "Test Input" };
//third out parameter
var param3 = new SqlParameter { ParameterName = "@paramName3",
SqlDbType = SqlDbType.VarChar, Direction = ParameterDirection.Output, Size = 255 };
//compose the SQL
var SQLString = "EXEC [dbo].[name of the Stored Proc] @paramName1, @paramName2, @paramName3";
//Execute the stored procedure
var employees= DataContext.Employee.SqlQuery(SQLString, param1, param2, param3);
//or you can execute the SP using below
//var employees = DataContext.Database.SqlQuery<Employees>
(SQLString, param1, param2, param3)
DataContext
would be the name of your DataContext
Instance variableresultset
returned by the SP would be mapped to the IEnumerable
collection of Entity - The above sample would return IEnumerable<Employee>
<DataContext>.DataBase.SqlQuery
method or <DataContext>.<EntityName>.SqlQuery
out
param declared would have value returned by SPMARS = true - MultipleActiveResultSets=true
标签:
原文地址:http://www.cnblogs.com/zeroone/p/4604152.html