Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-blocking query result #340

Closed
oruchreis opened this issue Mar 19, 2022 · 4 comments
Closed

Non-blocking query result #340

oruchreis opened this issue Mar 19, 2022 · 4 comments

Comments

@oruchreis
Copy link

Hi,
As far as I saw in source code, GridServer.ItemsToDisplay calls blocking ToList method of IQueryable. This line blocking current thread:

AfterItems = itemsToProcess.ToList(); //select from db (in EF case)

Are there any plans to implement async version of GridServer to use non-blocking ToListAsync method? Or are there an other way to use ToListAsync instead?

@gustavnavar
Copy link
Owner

Hi,

System.Linq does not implement any async method, it only implements the ToList method. And System.Linq is currently the only requirement to build queries in the GridCore package. EF Core is not required.

If we wanted an async implementation to materialize the list of items to be shown on the screen, then EF Core must be used. EF Core includes an extension for IQueriable object to get an async list. But I didn't want to have this dependency because EF Core is not always used. So using ToList is a lesser evil.

If you have any idea about this, please let me know.

@oruchreis
Copy link
Author

I understand that the library should not be depent on EF Core or any other orm, and I agree with that. But it could be solved by an abstraction layer like an interface or something else. For instance of using an interface, it can be capable of running queries in sync and async manner, and someone else like me can implement this interface and register to DI to change behavior of querying like using EF core.

@gustavnavar
Copy link
Owner

GriBlazor 3.2.3 supports one of the following methods to get ItemsDTO object:
* server.ItemsToDisplay returns the object using the standard ToList method of the IQueryable<T> object supplied by System.Linq package
* await server.GetItemsToDisplayAsync(Func<IQueryable<T>, Task<IList<T>>> toListAsync) returns the object using a customtoListAsync method of the IQueryable<T> object. This method can be supplied by an ORM like EF Core. In this case we can call await server.GetItemsToDisplayAsync(async x => await x.ToListAsync())

@oruchreis
Copy link
Author

I didn't expect it so fast, I appreciate that thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants