.net - Execute a query multiple times -
according dapper documentation, can execute same command multiple times if pass ienumerable
parameter:
connection.execute(@"insert mytable(cola, colb) values (@a, @b)", new[] { new { a=1, b=1 }, new { a=2, b=2 }, new { a=3, b=3 } } ).isequalto(3); // 3 rows inserted: "1,1", "2,2" , "3,3"
i similar query. same query executed multiple times , result of each execution, scalar value, combined in ienumerable
result. this:
ienumerable<long> ids = connection.query(@"insert mytable(cola, colb) values (@a, @b); select case(scope_identity() bigint);", new[] { new { a=1, b=1 }, new { a=2, b=2 }, new { a=3, b=3 } } );
when try this, invalidoperationexception
message "an enumerable sequence of parameters (arrays, lists, etc) not allowed in context". there way accomplish this?
i using dapper 1.50.2.
the api not provide functionality. need execute query multiple times each parameter argument.
var sql = @"insert mytable(cola, colb) values (@a, @b); select case(scope_identity() bigint);"; var parameters = new[] { new { a=1, b=1 }, new { a=2, b=2 }, new { a=3, b=3 } }; list<long> ids = new list<long>(); foreach(var param in parameters) { ids.addrange(connection.query<long>(sql, param)); }
Comments
Post a Comment