我想将大量数据从 F# 传输到 SQL 表。基本上,我的 F# 代码创建了一个由三列(UserID、ProductID 和 Price
)和 N 行组成的矩阵。我想将其“复制/粘贴”到数据库中
我尝试了多种选择,但最终,从 F# 传输数据非常慢(10000 行大约需要 1 小时)。
感谢上一个问题的回答 如何包含存储的在 F# 中,解决此问题的一个有趣方法是使用 SqlBulkCopy
。
SqlBulkCopy
的 WritetoServer
方法需要数据库类型,但我没有找到任何现有代码或将矩阵转换为数据库的简单方法。
您有什么建议或想法吗?
I want to transfer a large amount of data from F# to an SQL table. Basically my F# code creates a matrix of three columns (UserID, ProductID and price
) and N lines. I would like to "copy/pate it" into a database
I tried several options but at the end, the transfer of data from F# is really slow (around one hour for 10000 lines).
Thanks to answers of a previous question How to include a stored procedure in F#, an interesting way to resolve this problem is to use SqlBulkCopy
.
SqlBulkCopy
requires a database type for its WritetoServer
method but I didn't find any existing code or simple way to convert a matrix into a database.
Do you have any suggestions or ideas?
发布评论
评论(2)
这应该可以帮助您开始(并参考文档 有关
SqlBulkCopy
的更多信息):This should get you started (and reference the documentation for more information about
SqlBulkCopy
):如果您同意第三方库,fastmember 在这里真的很有用。
这给您留下了一个通用方法,您可以将任何
seq
汇集到其中。还有一些配置参数,您当然可以根据需要进行配置。If you're okay with third party libraries, fastmember can be really useful here.
This leaves you with a generic method that you can just funnel any
seq<a'>
into. Along with some config parameters, which you can of course configure to your needs.