C# 独立的<;字符串,对象>;对象有多个对象,如何分离?

C# 独立的<;字符串,对象>;对象有多个对象,如何分离?,c#,membership-provider,mongodb-.net-driver,C#,Membership Provider,Mongodb .net Driver,我目前正准备开发一个以asp.NETMVC4和mongodb为数据库的网站。由于Microsoft成员资格提供程序只支持SQL-DB,因此我必须使用另一个成员资格提供程序。我决定使用ExtendedMongoMembership提供程序。只要在帐户创建过程中没有传递其他用户属性,一切都正常。当我尝试添加一些附加属性(如电子邮件)时,CreateUserRow函数的功能会抛出和异常。我已经下载了源代码并尝试修复它。因此,我必须在对象内部分离对象,这似乎是将必要的数据传递到函数中的方式 publi

我目前正准备开发一个以asp.NETMVC4和mongodb为数据库的网站。由于Microsoft成员资格提供程序只支持SQL-DB,因此我必须使用另一个成员资格提供程序。我决定使用ExtendedMongoMembership提供程序。只要在帐户创建过程中没有传递其他用户属性,一切都正常。当我尝试添加一些附加属性(如电子邮件)时,CreateUserRow函数的功能会抛出和异常。我已经下载了源代码并尝试修复它。因此,我必须在对象内部分离对象,这似乎是将必要的数据传递到函数中的方式

 public bool CreateUserRow(string userName, IDictionary<string, object> values)
    {
        string userTableName = "Users";
        List<BsonElement> elements = new List<BsonElement>();
        elements.Add(new BsonElement("UserName", userName));
        elements.Add(new BsonElement("_id", GetNextSequence("user_id")));
        if (values != null)
        {
           // Here I'm facing the problem where I have to get the property names
           // and the values to add them to the elements list
           // The IDictionary is unfortunately not build in the way
           // propertyname,value so that I could get the entries in an easy way

        }

        var collection = _provider.GetCollection(userTableName);
        var result = collection.Insert(new BsonDocument(elements.ToArray()));
        return result.LastErrorMessage == null;
    }
public bool CreateUserRow(字符串用户名、IDictionary值)
{
字符串userTableName=“Users”;
列表元素=新列表();
添加(新的bsonement(“用户名”,UserName));
添加(新的bsonement(“\u id”,GetNextSequence(“user\u id”));
如果(值!=null)
{
//在这里,我面临的问题是,我必须获得属性名称
//以及要将其添加到元素列表中的值
//不幸的是,IDictionary没有以这种方式构建
//propertyname,值,以便以简单的方式获取条目
}
var collection=\u provider.GetCollection(userTableName);
var result=collection.Insert(新的BsonDocument(elements.ToArray());
返回result.LastErrorMessage==null;
}
IDiconnary包含4个名为(Comparer、Count、key、Values)的键,这些键的名称及其计数是固定的。用于写入数据库的属性名作为单个对象存储在一个对象中,该对象是在命令行中带有键“Keys”的值。这同样适用于db的值,这些值也存储在一个对象中,该对象是一个键为“values”的值。我的问题是我不知道如何分离这些物体。下面的图片显示了调试会话期间字典的结构

如何访问存储为值的对象内部的对象

编辑: 现在找到了一条路,还有更好的吗

        var propnames = ((IEnumerable<object>) values["Keys"]).ToArray();
        var propvalues = ((IEnumerable<object>)values["Values"]).ToArray();
        dynamic test;
        for (int i = 0; i < propnames.Count(); i++)
        {
            Type type = propvalues[i].GetType();

            test = Convert.ChangeType(propvalues[i], type.UnderlyingSystemType);
            //BsonValue bsonValue = test as BsonValue;
            elements.Add(new BsonElement(propnames[i] as string,test ));
        }
var-propnames=((IEnumerable)值[“键]).ToArray();
var propvalues=((IEnumerable)values[“values”]).ToArray();
动态试验;
对于(int i=0;i
这个问题实际上与mongo db无关。它可以是任何非SQL Server存储。