This is a migrated thread and some comments may be shown as answers.

[Solved] Problem with CustomBinding (DbIsNullExpression)

3 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stefan
Top achievements
Rank 1
Stefan asked on 31 Jan 2012, 11:26 AM
Hello,
I'm having a problem during Filtering with CustomBinding enabled. It keeps throwing exceptions in my face. For brevities sake I attached a sample project. I sincerely hope I'm just doing something wrong, but I can't figure out what.

Also I think this problem is loosely related to http://www.telerik.com/community/forums/aspnet-mvc/grid/the-argument-to-dbisnullexpression-must-refer-to-a-primitive-or-reference-type.aspx

Thanks in advance,
Stefan

3 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 31 Jan 2012, 12:05 PM
Hello Stefan,

Looking at the code you have attached, it seems that a projection is made before the filtering which actually triggers the error. Therefore, changing  the code similar to the following should correct the issue:

public IEnumerable<InventoryItemViewModel> FindByCommand(GridCommand command)
{
    var data = _context.InventoryItems.AsQueryable();
 
    if (command.FilterDescriptors.Any())
        data = data.Where(ExpressionBuilder.Expression<InventoryItem>(command.FilterDescriptors));
 
    return data.Select(x => new InventoryItemViewModel
    {
        Id = x.Id,
        Name = x.Name
    });
}

If you would like to keep the projection before the filtering expression is added, the query should be executed after the projection

All the best,
Rosen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Stefan
Top achievements
Rank 1
answered on 31 Jan 2012, 01:37 PM
Guess that means meddling around with the FilterDescriptors where the names of the Model and ViewModel don't line up, right? 
For example I have property ArticleName on the ViewModel and Article.Name on the Model, which will probably choke the ExpressionBuilder.

If so, that sounds more like a workaround then a solution, but that's probably good enough for now.
0
Luis
Top achievements
Rank 1
answered on 07 Jul 2012, 05:17 PM
I published a project that can help you in this situation.
You can find it
on Codeplex and Nuget, please take a look.

http://tgh.codeplex.com/ 

https://nuget.org/packages/TelerikMvcGridCustomBindingHelper 
Tags
Grid
Asked by
Stefan
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Stefan
Top achievements
Rank 1
Luis
Top achievements
Rank 1
Share this question
or