Raven DB - Have it Auto Generate its own Key

一曲冷凌霜 提交于 2019-12-04 07:45:32

You can use this if you want Id to be a property that you control on your own and have raven use another property as the documents id instead:

public class User
{
    public string DocumentId { get; set; }
    public Guid Id { get; set; }
    public string Name { get; set; }

    public User()
    {
        Id = Guid.NewGuid();
    }
}

documentStore.Conventions.FindIdentityProperty = prop =>
{
    if (prop.DeclaringType == typeof(User))
        return prop.Name == "DocumentId";

    return prop.Name == "Id";
};
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!