【问题标题】:kendo ui ToDataSourceResult support mongodb C# driverkendo ui ToDataSourceResult 支持 mongodb C# 驱动
【发布时间】:2016-09-12 00:05:31
【问题描述】:

我在我的项目(客户端)和我的网格中具有 Kendo ui Grid FilterAble 和 Sortable 并且 ... 为 true 并在服务器端操作上设置

但我的数据库是 mongodb,现在在我的客户端用户集过滤器中 我收到了这个错误

MongoDB.Driver.dll 中出现“System.InvalidOperationException”类型的异常,但未在用户代码中处理 附加信息:不支持 Compare({document}{Name}.ToLower(), "test")。

因为我使用 webapi 我创建自己的 DataSourceRequest 类而不继承 当我想用这种方法将我自己的类转换为 DataSourceRequest 时(对于 filterAble )

 if (model.Filter != null && model.Filter.Filters.Count > 0)
        {
            var filters = new FilterDescriptorCollection();

            foreach (var f in model.Filter.Filters)
            {
                FilterDescriptor filter = new FilterDescriptor()
                {
                    Member = f.Field,
                    Operator =(FilterOperator)f.Operator,
                    Value = f.Value
                };
                filters.Add(filter);
            }

            request.Filters = filters;
        }

这是我的仓库

 var result = _context.Additives.AsQueryable().Select(a => new AdditiveList()
        {
            Id = a.Id.DbId,
            Name = a.Name,
            CurrentWeight = a.CurrentWeight,
            InitialWeight = a.InitialWeight
        }).ToDataSourceResult(model.ToDataSourceRequest());

现在我有这个问题 我错了过滤器创建? 或者 kendo 不支持 mongo 操作,我必须为自己写这个吗?

tnk

【问题讨论】:

  • 你觉得Compare({document}{Name}.ToLower(), "test")怎么样?您是否可以将该代码块放入您的项目中,包括这部分(Compare({document}{Name}.ToLower(), "test") 在您的问题中?
  • 这个块由 kendo ui (ToDataSourceResult) 创建我添加存储库代码
  • Additives 中有NULL 值的name 吗?尝试用其他 null 数据填充所有 name 字段值并再次测试。应用这些更改后您是否看到错误?
  • 我的名字没有空值

标签: c# mongodb web asp.net-web-api kendo-ui


【解决方案1】:

我发现我的问题 在我的过滤器类(模型)中,我有一个枚举,我的枚举有错误的值 我将我的枚举更改为这个值

 public enum MyFilterOperator
{
    Lt,
    Lte,
    Eq,
    Neq,
    Gte,
    Gt,
    Startswith,
    Endswith,
    Contains,
    IsContainedIn,
    Notsubstringof,
    IsNull,
    IsNotNull,
    IsEmpty,
    IsNotEmpty
}

现在一切正常

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-11
    • 2018-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多