MongoDB C # Serializing Drivers with Dynamic Objects

I have a model that looks like this:

public class Record { public Record() { Created = DateTime.Now; } public string Id { get; set; } public string ApplicationId { get; set; } public Dictionary<string, dynamic> Values { get; set; } public DateTime Created { get; set; } } 

which is stored in MongoDB using the MongoDB C # driver. This works GREAT when I do things like:

 { applicationId: "52f52db8008a280f583c9ff6", values: { "52f9410a324e68055f39f8c0": 245234 "52f941096d82a531e700e56b": "sdfasdf" "52fa4a96e0b2e0d4e61d0a03": "52fa4a9b91c477e367ab99e6" } } 

but when I try to add an array of strings, for example:

 { applicationId: "52f52db8008a280f583c9ff6", values: { "52f9410a324e68055f39f8c0": 245234 "52f941096d82a531e700e56b": "sdfasdf" "52fa4a96e0b2e0d4e61d0a03": "52fa4a9b91c477e367ab99e6" "52fa85ea16f04a6151e4ea51": [ "52fa85f2d2ffa4cbdcf538e8", "52fa85f205505f671f3d0d7b"] } } 

It gives me the following error when I try to execute a GET in a document:

 An exception of type 'System.IO.FileFormatException' occurred in MongoDB.Driver.dll but was not handled in user code Additional information: An error occurred while deserializing the Values property of class API.Models.Record.Record: Cannot create an abstract class. 

if I look at the database that he saved, but its really funky look:

enter image description here

Has anyone had experience in dynamics and mongo?

+7
c # dynamic mongodb mongodb-.net-driver
source share
1 answer

Update: dynamic now supported by the v2.0 driver.


You cannot use the dynamic driver and MongoDB C #. Here's a jira ticket about it.

From the description:

We have not yet determined in which version we could add support for C # dynamic types. This ticket is a place where you can comment on the desirability of this feature and / or vote for it.

+6
source share

All Articles