In Dapper we have execute a command multiple times title that allow us to run query many time with different values. Is this possible in EF Core using ExecuteSqlRawAsync function as well?
Something like this:
_context.Database.ExecuteSqlRawAsync(myStringQuery, myParameters)
and this code should translate following query:
INSERT INTO MyTable (MyColumn)
VALUES (@p0, @p2)
Currently this method does work, but only adding first index of my list (first parameter only) and generate below query:
INSERT INTO MyTable (MyColumn)
VALUES (@p0)
My string query look like:
StringBuilder myStringQuery = new();
sb.AppendLine("query ... VALUES ({0})")
I have to solve problem in this way for now
StringBuilder sb = new();
sb.AppendLine("INSERT INTO \"Blogs\"");
sb.AppendLine($"(\"{nameof(Blog.Url)}\")");
sb.AppendLine("VALUES");
int i;
for (i = 0; i < obj.Length - 1; i++)
{
sb.AppendFormat("({{{0}}}),", i);
}
sb.AppendFormat("({{{0}}})", i++);
await _context.Database.ExecuteSqlRawAsync(sb.ToString(), obj.Select(x => x.Url!));
but I want to solve this like in the Dapper version seen in this link