小编Shy*_*leg的帖子

将FilterDefinition <TDocument>转换为我可以在mongo shell中运行的常规json mongo查询

我有很多复杂的查询,我有时希望直接检查Mongo以进行调试\ explain().使用较新的2.0+ c#驱动程序,我不知道该怎么做.在以前的版本中有一个叫做的东西IMongoQuery,这个有用.

一个简单的例子:

FilterDefinition<LalalaEvent> filter = Builders<LalalaEvent>.Filter
    .Where(e => ids.Contains(e.Id) && e.Deleted != true );
Run Code Online (Sandbox Code Playgroud)

.net c# mongodb mongodb-csharp-2.0 mongodb-.net-driver

17
推荐指数
3
解决办法
1万
查看次数

Newtonsoft JSON.net反序列化错误,其中JSON中的字段更改顺序

这是从Android设备获取请求的WCF服务.相同的请求适用于Lollipop设备,而不是来自软糖设备,因为软糖在创建时以不同方式排列JSON.

例外:

反序列化对象时出现意外的标记:String.路径'SearchFilters.config.$ type',第1行,第212位.

不工作的Json:

{
    "DeviceType": 2,
    "SearchFilters": {
        "config": {
            "$values": [
                {
                    "Collection": {
                        "DeviceType": 2
                    },
                    "Category": ""
                }
            ],
            "$type": "System.Collections.Generic.List`1[[Yoosh.SharedClasses.YooshConfig, YooshSharedClassesDll]], mscorlib"
        }
    },
    "RequestingUserId": "66666666-6666-6666-6666-666666666666",
    "APIKey": "xxx"
}
Run Code Online (Sandbox Code Playgroud)

工作Json:

{
    "APIKey": "xxx",
    "DeviceType": 2,
    "RequestingUserId": "66666666-6666-6666-6666-666666666666",
    "SearchFilters": {
        "config": {
            "$type": "System.Collections.Generic.List`1[[Yoosh.SharedClasses.YooshConfig, YooshSharedClassesDll]], mscorlib",
            "$values": [
                {
                    "Category": "",
                    "Collection": {
                        "DeviceType": 2
                    }
                }
            ]
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有些字段的顺序不同.这是唯一的区别.

C#类:

public class QueryParameters 
{
    BaseParameters m_baseParameters;
    Guid m_gRequestingUserId;
    Dictionary<string, object> m_SearchFilters;

    [DataMember] …
Run Code Online (Sandbox Code Playgroud)

c# json.net

10
推荐指数
1
解决办法
1512
查看次数