linmasaki/KendoNET.DynamicLinq

Async Extension

luizfbicalho opened this issue ยท 11 comments

Have you ever consider to make ?

.ToDataSourceResultAsync(request)

Maybe I will add this feature in the future, but I think is not necessary now. Thank for your advice ๐Ÿ˜ƒ

If I could help in this.

`

 public static async Task<DataSourceResult> ToDataSourceResultAsync<T>(this 
 Task<IQueryable<T>> queryable, int take, int skip, IEnumerable<Sort> sort, Filter filter, 
 IEnumerable<Aggregator> aggregates, IEnumerable<Group> group)
    {
        var waitedQueryable = await queryable;
        var errors = new List<object>();

        // Filter the data first
        waitedQueryable = Filter(waitedQueryable, filter, errors);

        // Calculate the total number of records (needed for paging)            
        var total = await waitedQueryable.CountAsync();

        // Calculate the aggregates
        var aggregate = Aggregates(waitedQueryable, aggregates);

        if (group != null && group.Any())
        {
            //if(sort == null) sort = GetDefaultSort(queryable.ElementType, sort);
            if (sort == null) sort = new List<Sort>();

            foreach (var source in group.Reverse())
            {
                sort = sort.Append(new Sort
                {
                    Field = source.Field,
                    Dir = source.Dir
                });
            }
        }

        // Sort the data
        waitedQueryable = Sort(waitedQueryable, sort);

        // Finally page the data
        if (take > 0)
        {
            waitedQueryable = Page(waitedQueryable, take, skip);
        }

        var result = new DataSourceResult
        {
            Total = total,
            Aggregates = aggregate
        };

        // Group By
        if ((group != null) && group.Any())
        {
            //result.Groups = queryable.ToList().GroupByMany(group);                
            result.Groups = waitedQueryable.GroupByMany(group);
        }
        else
        {
            result.Data = await waitedQueryable.ToListAsync();
        }

        // Set errors if any
        if (errors.Any())
        {
            result.Errors = errors;
        }

        return result;
    }

`

Thank you for your idea, I will check it later. ๐Ÿ˜ƒ

How about this?

How about this?

I add it to version 3.1.1. You can give me some feedback or recommendation if it is convenient. Thanks ๐Ÿ˜Š

Nice, thanks

I expected the async code to use the ToListAsync from EFCore
maybe receive the cancellation token

Uhhh...In my opinion, I want to keep this library simple and not depend too more on an external library.

P.S. I thought that .Net Core 2.2 may be able to use the way you suggested.

I understand, you're right not to put any mode dependencies.
maybe a async method that could receive an action to generate the ToList, this way I could create another extension and pass the action s=>s.ToListAsync() on the ToDataSourceAsync()

The current implementation uses Task.Run which will just spawn a threadpool thread. This is detrimental to some applications.

I think that this project isn't alive anymore