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

Add Cancellation Token Support #28

Open VictorioBerra opened 6 years ago

VictorioBerra commented 6 years ago

This is my first pass at solving https://github.com/AlexanderKrutov/DataTables.Queryable/issues/25

@AlexanderKrutov

Major changes:

Can you look at this pretty closely and make sure that it looks okay? https://github.com/AlexanderKrutov/DataTables.Queryable/commit/98a4a989c20fcd231b3d48aeb5eca84d6b48f371 I had to try and tap into the internals of EFCore to get access to the ToListAsync and CountAsync goodies.

Also, it would super nice if we had some really basic tests and TravisCI. We could have some broad integration tests just as smoke tests. I hit all the Samples and they all work perfectly. I did not make any major changes to the actual views or DT libraries but i made a small change for the POST example to POST JSON instead of form post.

VictorioBerra commented 6 years ago

See this issue on why Task.Factory.StartNew() is not good in aspnet core/ef core.

https://github.com/dncuug/X.PagedList/issues/61

The async implementation is using Task.Factory.StartNew() but that is not good in ASP.NET environment, it is better to be using the approach done by Entity Framework here because that is not creating a new thread.

VictorioBerra commented 6 years ago

Maybe just doing return await Task.Run(() => superset.ToList(), cancellationToken); is good enough instead of offloading all that to EF by detecting the query type and all that? Then you could keep your net40 support.

I am not sure if there is a big difference, I would need to check the ExecuteAsync code of EF Core.