OrientDB-NET.binary
OrientDB-NET.binary copied to clipboard
Error when retrieving an object with a field of type Dictionary<string, decimal>
I have a model that has a field of type Dictionary<string, decimal>, the decimal is necessary since its a financial payment data. I use to use double when i converted it to decimal it does not work. It says that it can not cast decimal in a generic list (paraphrased).
If you need i can submit the model and my test code. I tested this by creating a new db and creating the vertex class.
@dagimf Sorry about the late reply. if you could include your code sample that would be great
Here is the class i am using. Basically the exception happens when the ODocument is converted to c# equivalent model using the To method. The code i am using to run the program is below the class as well. I actually redesigned my db to not use dictionary, so i have found a work around.
The Model:
public class TestModel
{
public TestModel()
{
DecimalDictionaryTest = new Dictionary<string, decimal>();
DecimalListTest = new List<decimal>();
}
public decimal DecimalTest { get; set; }
public Dictionary<string, decimal> DecimalDictionaryTest { get; set; }
public List<decimal> DecimalListTest { get; set; }
}
The test code:
static void Main(string[] args)
{
//drop any previously exsisting db
try
{
OrientConnection.DropDatabase();
}
catch (Exception e)
{
Console.WriteLine(e);
}
//create the test database
OrientConnection.CreateDatabase();
//establish connection with the db
OrientConnection.CreatePool();
var database = new ODatabase(OrientConnection.GlobalDatabaseAlias);
//create the schema
database.Create.Class(typeof(TestModel).Name).Extends<OVertex>().Run();
//model to save
var testModel = new TestModel();
testModel.DecimalTest = decimal.Parse("189.5");
testModel.DecimalDictionaryTest.Add("key", decimal.Parse("189.5"));
testModel.DecimalListTest.Add(decimal.Parse("189.5"));
//save the test model
database.Insert<TestModel>(testModel).Run();
//get the saved data
var selectQuery = new OSqlSelect()
.Select()
.From(typeof(TestModel).Name)
.ToString();
var testModelDocuments = database.Query(selectQuery);
//convert it to the c# model
var testModels = testModelDocuments.Select(document => document.To<TestModel>()).ToList();
}