在 RavenDb 中存储我的对象时出现以下错误
我只为存储的对象分配了一个键,我正在使用重载的存储方法来存储实体。
Store 只被调用一次,为什么会抛出这样的异常。我不明白关于对象身份的一些事情。
Id
除了 ravendb 持久性之外,该属性还有另一个目的。
Entity UserQuery+MyItem had document key 'mykeypath/44' but now has document key property 'MyItems/44'. You cannot change the document key property of a entity loaded into the session
.
编辑以包含完整的源代码
void Main()
{
var host = "http://myhost:8020";
var _documentStore = new DocumentStore { Url = host, DefaultDatabase = "sdb" };
_documentStore.Initialize();
using (var session = _documentStore.OpenSession())
{
var path = "mykeypath/44";
session.Store(new MyItem { Id = 303, Test = "TEST" }, path);
session.SaveChanges();
}
}
public class MyItem : AuditableEntity {
public string Test { get; set; }
}
[Serializable]
public abstract class AuditableEntity : IAuditable
{
[DataMember]
[Display(Name = "Id", Description = "Id")]
public long Id { get; set; }
[DataMember]
[Display(Name = "Modified By", Description = "Modified By")]
public string ModifiedBy { get; set; }
[DataMember]
[Display(Name = "Modified Date", Description = "Modified Date")]
public DateTime ModifiedDate { get; set; }
}