MongoDB的C#驱动程序序列化与动态对象 [英] MongoDB C# Driver Serialization with dynamic objects

查看:511
本文介绍了MongoDB的C#驱动程序序列化与动态对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型,它是这样的:

I've got a model that looks like:

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; }
}

这是一个使用MongoDB的C#的驱动程序存储在MongoDB中。这个伟大的工程,当我做这样的事情:

that's 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 like:

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

它给了我下面的错误,当我尝试做文档上的GET:

It gives me the following error when I try to do a GET on the 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 it saved it but its really funky looking:

没有人有动力的经验和蒙戈?

anyone had any experience with dynamics and mongo?

推荐答案

更新: 动态现在支持的V2.0驱动程序。

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

您无法使用动态的MongoDB 的C#的驱动程序。这里有一个在 JIRA票一下吧。

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

这说明:

我们还没有确定在哪个版本,我们可能会增加对C#动态类型的支持。这票是一个地方,你可以在功能和/或选它的可取性发表意见。

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

这篇关于MongoDB的C#驱动程序序列化与动态对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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