我正在使用 RavenDB 4.0.6 的 BulkInsert 操作插入一堆产品:
using (var bulk = Store.BulkInsert())
{
foreach (var p in products)
{
p.Id = string.Empty; // <-- notice this
await bulk.StoreAsync(p);
}
}
请注意,我通过显式提供string.Empty
Id 属性的值来故意跳过标识符创建策略。这是基于 RavenDB 文档的Autogenerated ID's 部分。
运行代码时出现错误:
System.InvalidOperationException:文档 ID 必须具有非空值
由 BulkInsertOperation.cs 中的此代码片段直接生成。
我的问题是如何防止此错误并仍保持与其他代码相同的 ID 生成策略?
例如,我从不将 Id 属性设置为string.Empty
. 而且我担心将其设置为例如Guid.NewGuid.ToString()
可能会导致其他问题(也请参阅此问题)。