如何使用带有单个输入参数的EntityFramework在webApi中执行存储过程
本文关键字:EntityFramework webApi 存储过程 执行 参数 何使用 单个 输入 | 更新日期: 2023-09-27 18:20:27
我用一个输入参数制作了一个Sp。我正在尝试将它与我的Web服务绑定。但我不知道如何在我的服务中调用它,以及如何传递输入参数。这是我的sp
CREATE PROCEDURE StudentDetailss
@routeId varchar
AS
SELECT dbo.Users.FirstName, dbo.Users.LastName, dbo.PSS_Grades.GradeNo, dbo.PSS_Divisions.Name AS DivisionName, dbo.PSS_Stops.StopName,
dbo.PSS_ContactDeatils.Mobile, dbo.PSS_Routes.RouteId, dbo.PSS_Routes.RouteName, dbo.PSS_Students.StudentID, dbo.PSS_RelationShips.RelationshipID,
MIN(dbo.PSS_RelationShips.RelationTypeID) AS RelationTypeID, Users_1.FirstName AS ParentFname, Users_1.LastName AS ParentLname
FROM dbo.Users AS Users_1 INNER JOIN
dbo.PSS_ContactDeatils ON Users_1.UserID = dbo.PSS_ContactDeatils.UserID INNER JOIN
dbo.PSS_RelationShips INNER JOIN
dbo.Users ON dbo.PSS_RelationShips.StudentUserID = dbo.Users.UserID INNER JOIN
dbo.PSS_Routes INNER JOIN
dbo.PSS_Students INNER JOIN
dbo.PSS_Stops ON dbo.PSS_Students.StopId = dbo.PSS_Stops.StopId ON dbo.PSS_Routes.RouteId = dbo.PSS_Stops.RouteId ON dbo.Users.UserID = dbo.PSS_Students.StudentID AND
dbo.PSS_RelationShips.StudentUserID = dbo.PSS_Students.StudentID ON Users_1.UserID = dbo.PSS_RelationShips.RelatedUserID INNER JOIN
dbo.PSS_Grades INNER JOIN
dbo.PSS_StudentDivisions ON dbo.PSS_Grades.GradeID = dbo.PSS_StudentDivisions.GradeID INNER JOIN
dbo.PSS_Divisions ON dbo.PSS_Grades.GradeID = dbo.PSS_Divisions.GradeID AND dbo.PSS_StudentDivisions.DivisionID = dbo.PSS_Divisions.DivisionID ON
dbo.PSS_Students.StudentID = dbo.PSS_StudentDivisions.StudentUserID
WHERE PSS_Routes.RouteId=@routeId
GROUP BY dbo.Users.FirstName, dbo.Users.LastName, dbo.PSS_Grades.GradeNo, dbo.PSS_Divisions.Name, dbo.PSS_Stops.StopName, dbo.PSS_ContactDeatils.Mobile,
dbo.PSS_Routes.RouteId, dbo.PSS_Routes.RouteName, dbo.PSS_Students.StudentID, dbo.PSS_RelationShips.RelationshipID, Users_1.FirstName, Users_1.LastName
HAVING (MIN(dbo.PSS_RelationShips.RelationTypeID) <> 3)
我已经完成了函数导入,并从这个SP创建了一个复杂的类型。现在我想在我的Api中调用它。怎么可能
如果你已经导入了你的函数,它将可以通过上下文对象访问,如下所示:
public IEnumerable<StudentDetailss_result> GetStudentDetails(string routeId)
{
using(var ctx = new YourContextHere())
{
var result = ctx.StudentDetailss(routeId);
return result.ToList();
}
}