在我的应用程序(VS2015,C#,WebForm)中,我有以下代码,以前(在本地和生产服务器上)完全正常工作,但现在我得到错误:ObjectParameter没有从存储过程中获得输出值
存储过程中插入一个项目:
CREATE PROCEDURE [dbo].[StoredProcedure_Item_Insert]
@ItemText VARCHAR(250),
@InsertedID INT OUTPUT
INSERT INTO [dbo].[Item] ([ItemText])
VALUES (@ItemText -- ItemText - varchar(250)
);
SET @InsertedID = SCOPE_IDENTITY();
SELECT @InsertedID AS InsertedID;
库代码:在此存储过程
public int InsertItem(string itemText)
{
ObjectParameter InsertedId = new ObjectParameter("InsertedID", -1);
_db.StoredProcedure_Item_insert(feeText, InsertedId);
return (int)InsertedId.Value;
}
进口功能文件
Returns a Collection Of Scalars: Int32
当我点击Get Column Information button
,我得到
Name: InsertedID
EDM Type: Int32
Db Type: int
Nullable: true
唯一的变化作出我能想到的是,我的机器升级到Windows 10,所以我不得不重新安装VS2015。
我已经试过/发现:
InsertedId.Value
始终是-1- 错误消息是在“InsertedId` - > 'MappableType' - > 'DeclaringMethod'
在
DeclaringMethod
错误说((System.RuntimeType)InsertedId.MappableType).DeclaringMethod扔类型System.InvalidOperationException系统的异常。 Reflection.MethodBase {} System.InvalidOperationException
DeclaringMethod.Message
说方法只能在键入该Type.IsGenericParameter是真的被调用。
在存储过程中试图
OUT
和OUTPUT
- 尝试
SELECT @InsertedID
和RETURN @InsertedID
- 尝试
new ObjectParameter("InsertedID", typeof(Int32))
,而不是-1
第二个参数
我一直在试图找出什么现在正在进行这么多小时,但我完全卡住了...