RavenDB抛出型号命名空间变更后浇铸异常 [英] RavenDB throws casting exception after models namespace change

查看:176
本文介绍了RavenDB抛出型号命名空间变更后浇铸异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库中,我已存储几百个文档。目前,该系统的体系结构已发生变化,(其中包括)模型被迁移到不同的命名空间(在不同的部件)。

In the database, I have already stored hundreds of documents. Now the system architecture has changed and (among others) models was migrated into different namespace (in different assembly).

下面,样本文件的元数据显示:

Below, metadata of sample document is shown:

和code我使用获取该文件:

and code I'm using to fetch such document:

var configuration = documentSession.Load<One.Social.Core.Entities.Setting>("Setting");

会抛出异常铸造:

which throws casting exception:

[InvalidCastException: Unable to cast object of type 'One.QA.Core.Entities.Setting' to type 'One.Social.Core.Entities.Setting'.]

更新:

Similiar错误,但是从NewtonsoftJson上升,而我收藏的dosument,现在改为内部指定类型的。

Similiar error but from NewtonsoftJson rises, while I have collection of specified type inside the dosument, which now changed.

在数据库中,我有问题的文件,其中包含答案的列表:

In database I have Question document, which contains a list of Answers:

在code,类型看起来像这样:

In the code, the type looks like that:

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&LT;>,没有ICollection的&LT;>。我不需要 $类型元,现在,它应该是:

Answers namespace changed. In addition, now it's derived from IList<>, no ICollection<>. I don't need the $type meta now, it should be:

.

虽然这是一个列表现在,一个错误,因为旧的 $类上涨信息:

While it is a list now, an error rises because of the old $type information:

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'.

什么是迁移的所有文件,以反映当前的类型名称的最佳方法是什么?是否有任何内置的机制?

What is the best way to migrate all documents to reflect current types names ? Is there any built in mechanism ?

顺便说一句:我使用的是RavenDB - 建立#960

Btw: I'm using RavenDB - Build #960

推荐答案

亚雷克, 究其原因,问题是,你有两种类型。 如果删除QA类型,它只是工作。 或者,你可以做悦建议,并迫使这一点。

Jarek, The reason for the issue is that you HAVE both types. If you remove the QA type, it will just work. Or, you can do as Wyatt suggested and force this.

这篇关于RavenDB抛出型号命名空间变更后浇铸异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆