English 中文(简体)
RavenDB:在保存大量数据时处理128项限制的最佳做法是什么?
原标题:RavenDB: What is best practice for dealing with the 128 item limit when saving large amounts of data?
  • 时间:2012-05-28 12:51:52
  •  标签:
  • c#
  • ravendb

我正在将SqlServer数据库中的文件转移到RavenDB数据库中。 这一过程很简单, 但根据RavenDB安全第一原则, 只有第一批128份文件被实际存储。

我理解为什么会这样,我也知道这一限制可以对整个文件储存处进行调整,但是,鉴于在特定操作中储存128多份文件并不罕见,我想知道最佳做法是什么?

这是我的代码来展示我如何超越极限的例子。有更优雅的方法吗?

public static void CopyFromSqlServerToRaven(IDocumentSession db)
{
    var counter = 0;
    using (var connection = new SqlConnection(SqlConnectionString))
    {
        var command = new SqlCommand(SqlGetContentItems, connection);
        command.Connection.Open();
        using (var reader = command.ExecuteReader())
        {
            while (reader.Read())
            {
                counter++;
                db.Store(new ContentItem
                            {
                                Id = reader["Id"].ToString(),
                                Title = reader["Name"].ToString(),
                                Description = reader["ShortDescription"].ToString()
                            });
                if (counter < 128) continue;
                db.SaveChanges();
                counter = 0;
            }
        }
        db.SaveChanges();
    }
}
最佳回答

您可以在一个操作中存储多少文档。 不需要保存块的变化 。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签