Soheil Karami Soheil Karami - 2 months ago 60
C# Question

kendo ui ToDataSourceResult support mongodb C# driver

i Have Kendo ui Grid In My Project (client side) and in my grid FilterAble and Sortable and ... is true and set on serverSide operation

but my database is mongodb and now when in my client user set filter
i got this error


An exception of type 'System.InvalidOperationException' occurred in MongoDB.Driver.dll but was not handled in user code
Additional information: Compare({document}{Name}.ToLower(), "test") is not supported.


because i use webapi i Create My own DataSourceRequest Class without inheritance
when i want convert my own class to DataSourceRequest with this method(for 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;
}


this my repository

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());


now i have this question
i was wrong for filter Creating ?
or
kendo dont support mongo operation and i must write this for myself?

tnks

Answer

I find my problem in my Filter class (model) i have one enum and my enum has wrong value i change my enum to this values

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

and now every things work correctly