-
Notifications
You must be signed in to change notification settings - Fork 71
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
Insert multiple values (across different tables) using SqlCommand Provider #331
Comments
@sharno thanks for bringing in your questions. You can issue multiple SQL commands in a single command execution, but only the first resultset will be exposed as a return value, this is a limitation of SQL Server own meta data inspection mecanism that this library relies on. You can use output parameters for retrieving scalar values, or temp tables + separate select statements if you need several result sets. Performance wise, I haven't seen a big difference for simple tasks between issuing several
Performance wise, if your data is of exact shape of a valid subset of columns of physical table, you can use bulk insert facility from the library, that will offer vastly better performance than a batch of insert statements. If your data is a projection of a mix of user input (coming from your f# app memory) and things in your database, the best is to bulkinsert user input in temp table, and then use
This could be added to the library, more details on implementation can be discussed and PR always welcome. @VTJDailey that may be up your alley if you want to try a small contribution extending the library, the underlying machinery for async execution is already being used for @sharno could you add more specifics to the question? maybe a code sample of what you'd do in plain SQL or ADO.NET. |
@smoothdeveloper Also, I thought of using a table-valued parameter with a proc for more complicated queries, but I didn't get the time or chance to try it out yet. |
Could you post some of the specifics of your environment (IDE version, version of the library that has the issue), also, is there anything specific about the database schema you are connecting to? does it have large amount of objects? I think there is machinery in the TP SDK to make some of the work providing the types/members lazy in context of the IDE, but the current implementation of the provider is doing the inspection of the database wholesale AFAICS: FSharp.Data.SqlClient/src/SqlClient.DesignTime/SqlClientProvider.fs Lines 89 to 132 in b78ff71
I guess the least painful way for you to troubleshoot this would be to clone this repository, and add a test that would run the same code as highlighted above, outside of a provider context, and connects to your development database. This way we'd know how long that takes in your environment and hopefully figure some testing / fix ideas around the issue. https://fsprojects.github.io/SQLProvider/ provider has "Lazy schema exploration", @pezipink would you be able to hint if similar technique could be applied to the snipped above? |
@sharno I'm closing this issue, if you need to get more help, don't hesitate to open it again or create a new one. Thanks. |
Description
Is there a way to execute multiple commands in one round trip to the DB?
I want to have the Async execution capability of commands (so couldn't use SqlProgrammability) and at the same time execute multiple SqlCommands together in a certain order as a bullk operation on SQL Server.
edit: I realized I can insert a determined number of rows in each table in a single SqlCommand, but I'd like to insert an arbitrary number of rows
Could this be done currently?
The text was updated successfully, but these errors were encountered: