我当前有一个对象,它有一个名为 Id 的公共属性。当我存储对象时,我希望 Id 成为数据的一部分,而不是像当前那样成为文档 Id。创建文档存储时,我仅设置连接字符串。
using (var session = documentStore.OpenSession())
{
session.Store(a);
session.SaveChanges();
}
a can be thought of an object as:
public class A
{
public Guid Id { get; set; }
//other properties
}
因此,要么我希望它生成一个随机 Id,要么将数据和 documentId 都作为 A 类的 Id 属性。
EDIT:
所以有两种可能:
1. 文档Id = Id 和
Data Section contains:
{
data //sorry if the notation is not correct, doing it off of memory
{
Id: [my guid]
//other properities
}
}
或者包含Id和Document ID的数据=由raven随机生成
如果你愿意,你可以使用这个Id
成为您自己控制的属性,并让 raven 使用另一个属性作为文档 id:
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";
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)