Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试将其他对象与id关联(将对象保存到ravendb时)_C#_.net_Ravendb - Fatal编程技术网

C# 尝试将其他对象与id关联(将对象保存到ravendb时)

C# 尝试将其他对象与id关联(将对象保存到ravendb时),c#,.net,ravendb,C#,.net,Ravendb,我有以下代码,其中我创建了新对象并试图保存到raven数据库中。 我要走了 Raven.Client.Exceptions.UnuniqueObjectException 在RavenSession.Store上(retrievedUrl) 带有以下异常消息 An exception of type 'Raven.Client.Exceptions.NonUniqueObjectException' occurred in Raven.Client.Lightweight.dll but w

我有以下代码,其中我创建了新对象并试图保存到raven数据库中。

我要走了

Raven.Client.Exceptions.UnuniqueObjectException

在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。有关更多信息,请参见。

这意味着会话中已存在具有相同id的不同对象。我的解决方法是使用新会话。或者,您可以根据

复制值,其中是
retrievedUrl=newretrievedURL{Id=url.Id,url=url.url}中的
url
对象来自哪里?
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'.