使用 subsonic 2.2 批量插入到不同的提供商

发布于 2024-12-21 07:43:49 字数 747 浏览 3 评论 0原文

我有一个 IEnumerable,我想批量插入(240,000 多条记录)。我一直在仔细阅读论坛,所以我一直无法想出一些有用的东西...

另一个问题是我需要能够指定不同的提供者,因为这些记录需要插入到具有不同连接字符串的数据库。

基本上,是这样的:

IEnumerable<MyObject> records = GetRecords();
SubSonicDooHickey.BatchSave(records, "differentSubsonicProvider")

我知道这不准确,但是沿着这些思路...

我已经尝试过:(

var itemsToSaveCollection = new ItemCollection(); // Your collection type here

foreach (var xmlItem in xmlItems)
{
    var item = new Item(); // Your data model type here
    // Set item values from xml
    itemsToSaveCollection.Add(item);
}

itemsToSaveCollection.BatchSave();

以及其他几个)但无法让它们工作...上面的代码不起作用因为我无法从 subsonic 中找到具有 .BatchSave 功能的合适集合,而且我也不知道如何更改提供程序。

I have an IEnumerable and I would like to do a batch insert (240,000+ records). I've been perusing the forums and SO and I haven't been able to come up with something that works...

The other catch is that I need to be able to specify a different provider, as these records need to be inserted into a database with a different connection string.

Basically, something like this:

IEnumerable<MyObject> records = GetRecords();
SubSonicDooHickey.BatchSave(records, "differentSubsonicProvider")

I know that isn't exact, but something along those lines...

I've tried:

var itemsToSaveCollection = new ItemCollection(); // Your collection type here

foreach (var xmlItem in xmlItems)
{
    var item = new Item(); // Your data model type here
    // Set item values from xml
    itemsToSaveCollection.Add(item);
}

itemsToSaveCollection.BatchSave();

(and several others) but couldn't get them to work...the above code didn't work because I couldn't find an appropriate collection from subsonic that had a .BatchSave function on it, and I also wouldn't know how to change the provider.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

硬不硬你别怂 2024-12-28 07:43:49

事实证明我不需要这个,但我可以使用命令让它工作:

var sql = "insert into foo(col1) values('@Param1'),('@Param2')";

var cmd = new QueryCommand(sql, repositoryName);
cmd.AddParameter("@Param1", "value1", DbType.String);
cmd.AddParameter("@Param2", "value2", DbType.String);
DataService.ExecuteQuery(cmd)

Turns out I didn't need this, but I was able to get this to work using a command:

var sql = "insert into foo(col1) values('@Param1'),('@Param2')";

var cmd = new QueryCommand(sql, repositoryName);
cmd.AddParameter("@Param1", "value1", DbType.String);
cmd.AddParameter("@Param2", "value2", DbType.String);
DataService.ExecuteQuery(cmd)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文