I want to migrate the whole SQL database to Cosmos DB.in this process one of the SQL table columns have a serialize data as follows
[{"Id":"1","Type":"Phone","HeaderLabel":"HQ - Main Line","ContactNumber":"+9122222222"}]
the serialized data represent a Class
public class ContactNumber
{
public string ContactNumberId { get; set; }
public string Type { get; set; }
public string HeaderLabel { get; set; }
public string ContactNumber { get; set; }
}
while saving the data in sql i have to perform the Serialization and Deserialization for the class which ncessary to do.
public string _ContactNumbers { get; set; }
public List<ContactNumber> ContactNumbers
{
get { return _ContactNumbers == null ? null : JsonConvert.DeserializeObject<List<ContactNumber>>(_ContactNumbers); }
set { _ContactNumbers = value == null ? null : JsonConvert.SerializeObject(value); }
}
after using the migration tool it gets updated like this
"ContactNumbers":"[{\"Id\":\"1\",\"Type\":\"Phone\",\"HeaderLabel\":\"HQ - Main Line\",\"ContactNumber\":\"+9122222222\"}]"
the class remains the same. while fetching the data from cosmos DB I have not performed any Serialization and Deserialization.
public List<ContactNumber> ContactNumbers
while fetching the data it throws an error
Error converting value "[{"Id":"1","Type":"Phone","HeaderLabel":"HQ - Main Line","ContactNumber":"+9122222222"}]" to type 'System.Collections.Generic.List`1[CosmosDB.Models.ContactNumber]'. Path 'ContactNumber', line 1, position 2411.
the Error comes because of the Extra \ character in the string which is added after the migration.
I don't want to Serialization and Deserialization the class in cosmos DB because it not necessary to do it.
so how can I avoid the extra \ while migrating the data from SQL Database to Cosmos DB Document?