I am using the BulkInsert operation of RavenDB 4.0.6 to insert a bunch of products:
using (var bulk = Store.BulkInsert())
{
foreach (var p in products)
{
p.Id = string.Empty; // <-- notice this
await bulk.StoreAsync(p);
}
}
Notice that I'm deliberately skipping the identifier creation strategy by explicitly providing string.Empty
as the value of the Id property. This is based on the RavenDB docs, section Autogenerated ID's.
When running the code I get the error:
System.InvalidOperationException : Document id must have a non empty value
Which is directly produced by this codesnippet in BulkInsertOperation.cs.
My question is how I can prevent this error and still keep the same ID-generation strategy as my other code does?
E.g. I never set the Id property to anything other than string.Empty
. And I'm afraid that setting it to, for example, Guid.NewGuid.ToString()
might cause other issues (see this question as well).
For bulk operations, you have to either leave the Id property null (not empty string) to have it auto-generate a sequential ID, or generate a Guid ID manually.
The API is a bit inconsistent between bulk inserts and session inserts: