我必须在ef core 1.1.2上执行sql命令:
var projectParam = new SqlParameter("@projectid", SqlDbType.UniqueIdentifier).Value = inventory.ProjectId;
var locationParam = new SqlParameter("@locationid", SqlDbType.UniqueIdentifier).Value = location.Id;
var scanOrderParam = new SqlParameter("@scanorder", SqlDbType.Int).Value = scanOrder;
_ctx.Database.ExecuteSqlCommand("update Inventories set ScanOrder=ScanOrder+1 where ProjectId = '@projectid' AND LocationId = '@locationid' AND ScanOrder>'@scanorder';",
parameters: new[] {
projectParam, locationParam, scanOrderParam
});
抛出异常:
在ef core中使用参数的正确方法是什么?
编辑(解决方案): 问题是我声明参数并给它们值的方式。如果我使用这个表格,它可以工作:
var projectParam = new SqlParameter("@projectid", SqlDbType.UniqueIdentifier);
projectParam.Value = inventory.ProjectId;
var locationParam = new SqlParameter("@locationid", SqlDbType.UniqueIdentifier);
locationParam.Value = location.Id;
var scanOrderParam = new SqlParameter("@scanorder", SqlDbType.Int);
scanOrderParam.Value = scanOrder;
答案 0 :(得分:1)
var queryItem = new SqlParameter("@table", SqlDbType.Char) {Value = yourValue};