AlexanderKrutov / DataTables.Queryable

.Net library for clever processing of requests from datatables.net jQuery plugin on the server side (ASP.NET, Nancy or any other web server).
MIT License
51 stars 19 forks source link

Allow to access complex models properties #7

Closed dedo1911 closed 7 years ago

dedo1911 commented 7 years ago

Working out a fix for #6

dedo1911 commented 7 years ago

I wasn't able to create a variable BuildStringContainsPredicate in QueryableExtensions.cs:154 That takes care of the differen type which the predicate gets build with.

Columns derivated from child properties are not searchable neither orderable.

AlexanderKrutov commented 7 years ago

@dedo1911, thank you for the pull request! The case is more complicated than it may seem. It should be investigated more deeply. I've understood the idea and plan to refactor the library logic in order to support searching/ordering by nested properties. As a temporary workaround, you could use a wrapper model with plain properties, something like:

public class Address 
{
    public string Street { get; set; }
    public int House { get; set; }
}

public class User 
{
    public string Name { get; set; }
    public Address Address { get; set; }
}

var request = new DataTablesRequest<UserWrapper>(Request.QueryString);

var result = ctx.Users.Select(u => new UserWrapper() { 
    Name = u.Name, 
    AddressStreet = u.Address.Street, 
    AddressHouse = u.Address.House })
    .ToPagedList(request);
AlexanderKrutov commented 7 years ago

@dedo1911 Hi Dario, I am going to close your pull request because I have implemented the feature you requested in a little bit different way. Enumerating model properties is not needed anymore. If you are interested in, you can look into pull request #8. This will be included in release 1.5.0, nuget package will be updated soon. Anyway thank you for contributing and the idea!