【发布时间】:2016-09-16 08:32:42
【问题描述】:
我是 EF 新手,首先使用 EF 代码。刚刚获得了一个链接https://code.msdn.microsoft.com/How-to-retrieve-output-e85526ba,它首先显示了如何使用 EF db 的读取输出类型参数。所以有人告诉我如何先通过 EF 代码从存储过程中检索输出参数?
如果可能的话,给我小示例代码或将我重定向到相关文章。
谢谢
我有办法
var outParam = new SqlParameter();
outParam.ParameterName = "TotalRows";
outParam.SqlDbType = SqlDbType.Int;
outParam.ParameterDirection = ParameterDirection.Output;
var data = dbContext.Database.SqlQuery<MyType>("sp_search @SearchTerm, @MaxRows, @TotalRows OUT",
new SqlParameter("SearchTerm", searchTerm),
new SqlParameter("MaxRows", maxRows),
outParam);
var result = data.ToList();
totalRows = (int)outParam.Value;
【问题讨论】:
-
@ChrisBint 非常感谢您的链接。
-
我从没想过“OUT”能拯救我的一天。点赞!
标签: c# entity-framework stored-procedures