[英]Using Entity framework calling stored procedure return same value always
我目前正在使用SQL Server,ASP.net Web API 2和Entity Framework6技术开发应用程序。
我在下面有一个存储过程:
create procedure [dbo].[get_users_timesheets]
(
@user_id int,
@approved_type bit,
@location_id int,
@page_size int,
@page int,
@count int output
)
as
begin
DECLARE @SQL varchar(1000)
SET @SQL = 'select * from bs_user_timesheets WHERE
location_id='+STR(@location_id)
IF(@user_id!=-1) SET @SQL = @SQL + ' and user_id='+STR(@user_id)+''
if(@approved_type!='') set @SQL=@SQL+'and approved='+STR(@approved_type)+''
SET @SQL=@SQL+' order by [id] desc'
SET @SQL=@SQL+' OFFSET (('+STR(@page)+'-1)*'+STR(@page_size)+') ROWS'
SET @SQL=@SQL+' FETCH NEXT '+STR(@page_size)+' ROWS ONLY'
exec(@SQL)
SET @count = @@ROWCOUNT
end
我的问题是:一旦运行以下方法,而不是获取数据库中的实际记录数,无论我在其中存储了多少记录,我一直都在“ RetunValue”字段中得到“ 1”。
object[] parameter = {
new SqlParameter("@ParametterWithNummvalue", DBNull.Value),
new SqlParameter("@user_id",user_id),
new SqlParameter("@approved_type",approved_type),
new SqlParameter("@location_id",location_id),
new SqlParameter("@page_size",general.page_size),
new SqlParameter("@page",page),
new SqlParameter("@count", SqlDbType.Int) {Direction= ParameterDirection.Output}
};
var query = DB.Database.SqlQuery<bs_user_timesheets>("dbo.get_users_timesheets @user_id,@approved_type,@location_id,@page_size,@page,@count output", parameter);
var result = await query.ToListAsync();
var ReturnValue = ((SqlParameter)parameter[5]).Value;
如果有人向我展示如何解决此问题以获取“ ReturnValue”字段中的实际记录数,将不胜感激!
@@ Rowcount将返回受最后一条语句影响的行数。 我想最后一条语句总是会影响单个记录。 您应该直接执行查询以验证这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.