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:
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'.]
UPDATE:
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:
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; }
}
}
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 ?
Btw: I'm using RavenDB - Build #960
I had the same problem and ended up doing this:
Advanced.DatabaseCommands.UpdateByIndex(
"Raven/DocumentsByEntityName",
new IndexQuery {Query = "Tag:Album"},
new []{ new PatchRequest() {
Type = PatchCommandType.Modify,
Name = "@metadata",
Nested= new []{
new PatchRequest{
Name= "Raven-Clr-Type",
Type = PatchCommandType.Set,
Value = "Core.Model.Album, Core" }}}},
false);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With