我有以下代码,我创建新对象并尝试保存到 raven 数据库中。 ...
{
foreach (var url in urls)
{
MyUrl u = new MyUrl {
Id = url.Id,
Url = url.Url
};
urlsCollection.Add(u);
retrievedUrl = new RetrievedUrl {
Id = url.Id,
Url = url.Url
};
RavenSession.Store(retrievedUrl); //exception is thrown
RavenSession.SaveChanges();
}
我明白了
Raven.Client.Exceptions.NonUniqueObjectException
在RavenSession.Store(retrievedUrl);
带有以下异常消息
An exception of type 'Raven.Client.Exceptions.NonUniqueObjectException'
occurred in Raven.Client.Lightweight.dll but was not handled in user code
Additional information: Attempted to associate a different object
with id 'RetrievedUrl/361'.
最佳答案
您似乎正在尝试保存(至少)两个具有相同 ID 的不同对象,但这是不可能的。 RavenDB 在存储新文档时会自动创建唯一的 ID,但是,如果您显式定义文档 ID,则会使用该 ID。更多信息请参见 saving new document in raven .
关于c# - 尝试将不同的对象与 id 关联(将对象保存到 ravendb 时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27177071/