【问题标题】:RavenDB: Add auto increment to other property than ID in Raven 4.0RavenDB:在 Raven 4.0 中将自动增量添加到 ID 以外的其他属性
【发布时间】:2018-05-30 12:49:19
【问题描述】:

在 4.0 之前,我可以设置 here on SO 中提到的自动增量属性

但在 4.0 IDocumentStoreListener 中,HiLoKeyGenerator 已被移除。然而,我可以捕捉到保存像this on Raven Doc 这样的文档的事件。但是没有办法生成增量ID。是否有解决方法。 ?

    public class Product 
    {
       public string Id {get; set;}
       public int OtherIncrementalId {get; set;} 
    }

【问题讨论】:

    标签: c# asp.net ravendb auto-increment


    【解决方案1】:

    关于基于类型生成自定义 id 的文档: https://ravendb.net/docs/article-page/4.0/csharp/client-api/configuration/identifier-generation/type-specific

    如果你想为我尝试过的所有类型自定义 id 生成并且它可以工作:

     documentStore.Conventions.RegisterAsyncIdConvention<object>((dbname, obj) =>
     {
        return Task.FromResult(DocumentConventions.DefaultGetCollectionName(obj.GetType())+"/"+ YourCustomFunctionToGetNextId());
     });
    

    【讨论】:

      猜你喜欢
      • 2022-01-20
      • 2013-01-23
      • 2020-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-10
      相关资源
      最近更新 更多