Хранимая процедура для вставки элемента:
Код: Выделить всё
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
Код: Выделить всё
Name: InsertedID
EDM Type: Int32
Db Type: int
Nullable: true
Что я пробовал/нашел:
- всегда имеет значение -1
Код: Выделить всё
InsertedId.Value - Сообщение об ошибке находится в 'InsertedId` --> 'MappableType' --> 'DeclaringMethod'
- Ошибка в DeclaringMethod:
((System.RuntimeType)InsertedId.MappableType).DeclaringMethod выдал исключение введите System.InvalidOperationException System.Reflection.MethodBase {System.InvalidOperationException} - говорит
Код: Выделить всё
DeclaringMethod.Message
Метод можно вызывать только для типа, для которого Type.IsGenericParameter имеет значение true. - Проверил OUT и OUTPUT в хранимой процедуре
- Попробовал SELECT @InsertedID и RETURN @InsertedID
- Попробовал новый ObjectParameter("InsertedID", typeof(Int32)) вместо -1 для второго параметра
Подробнее здесь: https://stackoverflow.com/questions/404 ... -procedure