-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Non-tracking ExecuteInsert #29897
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Ran into a strong need for this on generating bulk data -- for the time being I just used a context factory to get around the ever-growing state of the change tracker and the overhead induced by that (nasty workaround but works), I've learned on EF Core for doing some lighter ETL and data generation but for some hefty datasets the change tracker is the number 1 thing in the way of performance. Only thing I'm somewhat hesitant about is dropping the return row count from the API, but as mentioned I can't really think of a use case that isn't served fine another way, and no weird "gotchas" there (triggers? I forget if those will show an inflated insert count if they do additional work -- I mean shows how much I read that value back out anyway) As EF Core has continued to mature it has been exciting watching things that require third party tooling slip into the mainline lib like |
@StrangeWill thanks for the feedback. FWIW for bulk insert you're probably looking for #27333; this issue here would be able getting EF to send INSERTs, whereas #27333 would be about using e.g. SqlBulkCopy. |
The primary benefit I see of this feature would be to do the equivalent of
There is no way to do this currently, and the alternatives mentioned do not allow selecting from an existing table directly on the server. So you would do something like what we already have for
to get the same result. |
@Charlieface |
EF Core 7.0 introduced ExecuteUpdate and ExecuteDelete, which are ways of updating and deleting database rows without passing through change tracking. For inserts, it's still necessary to go through the change tracker (Add and then SaveChanges).
There are two main advantages to this:
Notes:
At least in some DBs, returning an IQueryable allow embedding the insert in a CTE (WITH).
INSERT INTO foo (bar) VALUES (current_timestamp)
). This can also be useful to call some database function over a user-provided parameter (e.g. PG full-text search insertion, How to manually update a tsvector column? npgsql/efcore.pg#2317 (comment)). Note that there wouldn't be any query root here; only totally static functions make sense in this context. This also may intersect with server-side value converters (Support server side value conversions #10861), where a database function needs to be called on user-supplied data before inserting.The text was updated successfully, but these errors were encountered: