在数据库中,我已经存储了数百个文档。现在系统架构已经改变,并且(除其他外)模型被迁移到不同的命名空间(在不同的程序集中)。
下面显示了示例文档的元数据:
以及我用来获取此类文档的代码:
var configuration = documentSession.Load<One.Social.Core.Entities.Setting>("Setting");
这会抛出铸造异常:
[InvalidCastException: Unable to cast object of type 'One.QA.Core.Entities.Setting' to type 'One.Social.Core.Entities.Setting'.]
UPDATE:
类似的错误来自 NewtonsoftJson,而我在文档中有指定类型的集合,但现在已更改。
在数据库中,我有问题文档,其中包含答案列表:
在代码中,类型如下所示:
namespace One.Social.Ask.Web.Models
{
public class Question
{
public string Content { get; set; }
public IList<One.Social.Ask.Web.Models.Answer> Answers { get; set; }
}
}
答案名称空间已更改。另外,现在它派生自IList,不再是ICollection。我不需要$type
现在元,它应该是:
.
虽然现在是一个列表,但由于旧的,会出现错误$type
信息:
Newtonsoft.Json.JsonSerializationException: Error resolving type specified in JSON 'System.Collections.ObjectModel.Collection`1[[One.QA.Core.Entities.Answer, One.QA.Core]], mscorlib'. ---> Newtonsoft.Json.JsonSerializationException: Could not find type 'System.Collections.ObjectModel.Collection`1[[One.QA.Core.Entities.Answer, One.QA.Core]]' in assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
迁移所有文档以反映当前类型名称的最佳方法是什么?有什么内置机制吗?
顺便说一句:我正在使用 RavenDB - Build #960