Closed MargaretKrutikova closed 2 years ago
If this is a feature of SqlKata then it definitely could (and should) be added to SqlHydra!
Perhaps an entities
operation could be added to the insert
builder.
There is this overload of AsInsert
:
public Query AsInsert(
IEnumerable<string> columns,
IEnumerable<IEnumerable<object>> rowsValues)
that I think can be used for insert-many. Would be also nice to not have to pass a list of columns but automatically infer them as it is currently done for a single entity
.
That overload doesn't take returnId
as in input. Hopefully the current overload that takes KeyValuePair seq
will work for multiple columns.
Does SqlKata allow returning multiple ids for multiple inserts?
Ahh ok, I bet it does not support automatically returning identity fields for multiple inserts, which seems reasonable. That is probably why the overload for multiple inserts doesn't allow for the returnId
field.
SqlHydra could probably support this, but for v1 of this feature, I think it would be best to throw the following exception:
"getId
is not currently supported for multiple inserts via the entities
operation."
v0.530.0 has been published with multiple inserts via entities
operation.
Note that you since getId
is not supported for multiple inserts, you will need to replace it with excludeColumn
.
Was able to test it recently, everything works as expected. Thanks a lot for your help! This project looks like a fantastic solution to the eternal problem of having your database in sync with the code and avoiding tons of boilerplate, more robust and stable than data providers ❤️
I can't seem to find a way to do insert of multiple entities in one query, it does seem to be supported by
sqlkata
. Is there a way to achieve this withinsert
-computation expression?