0

鉴于:

在最初的帖子中,我试图调用db.Database.ExecuteCommand,从那时起我将其更改为您在此处看到的内容。(哪个有效)。执行命令总是返回0xfffff。SQLQuery 返回最后一个 select 语句的值或插入的行,具体取决于您的编码方式。

using (db=new MyEntites())
{
    var inserted = db.Database.SqlQuery<decimal>(query,parms}
}

查询中的最后两行是:

SET NOCOUNT OFF  
Select SCOPE_IDENTITY() AS newID  
4

2 回答 2

1

From the documentation for ExecuteSqlCommand method, the return value is

The result returned by the database after executing the command.

This means you need to RETURN the value in your procedure, not as a result set. So do this in your stored procedure as the last command:

RETURN SCOPE_IDENTITY()
于 2014-10-09T15:14:48.577 回答
0

感谢您的建议,第 1 步将这样的内容作为最后一次选择放入查询字符串中:

Select SCOPE_IDENTITY() as TESTID;

然后使用这种 EF 形式的 SQLQuery,十进制类型就是上面选择示例返回的类型。

using (db=new MyEntites())
{
   var identity = db.Database.SqlQuery<decimal>(query,parms}
}
于 2014-10-09T16:19:53.510 回答