Tengo que ejecutar un comando sql en ef core 1.1.2:
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
});
Se lanza la excepción:
¿Cuál es la forma correcta de usar parámetros con ef core?
Edición (solución): el problema fue la forma en que declaré los parámetros y les asigné valores. Si utilizo este formulario funciona:
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;
var queryItem = new SqlParameter("@table", SqlDbType.Char) {Value = yourValue};