-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Consider WithQueryTimeout through linq #29804
Comments
Is there any particular reason you're trying to avoid setting the timeout via context.Database? |
In NHibernate perspective, we are using future(lazy) queries and those queries not executed in order as you coded. |
This definitely isn't something EF supports; although we would like to one day allow batching multiple queries (#10879), but I'm not sure how they would be ordered otherwise than what the user specifies - maybe you can provide a bit of info on that? Note that it should be pretty easy to write an extension method over DbSet which accepts a LINQ query and a timeout, and sets the timeout via context.Database before executing the query. |
For backward compability we need to set timeout though IQuaryable interface is it possible somehow casting to ef internal class? IQueryable comes through DbSet public class IQueryableOptions
{
protected bool? Cacheable { get; private set; }
protected int? Timeout { get; private set; }
protected bool? ReadOnly { get; private set; }
public IQueryableOptions SetCacheable(bool cacheable)
{
Cacheable = cacheable;
return this;
}
public IQueryableOptions SetReadOnly(bool cacheable)
{
Cacheable = cacheable;
return this;
}
public IQueryableOptions SetTimeout(int timeout)
{
Timeout = timeout;
return this;
}
public static IQueryable<TEntity> Apply<TEntity>(IQueryable<TEntity> query) where TEntity : class
{
//TODO EFCORE We can handle IsReadonly but this might cause lazy property access runtime exception
//https://github.com/dotnet/efcore/issues/10042
/*if (ReadOnly == true)
{
query = query.AsNoTracking();
}*/
return query;
}
}
I think feature queries is not major feature considiring other gaps that we are struggling with. Such as ReadOnly/Query Only Navigation properties, Cascading Behaviors. |
You could probably create an extension method directly over DbSet, which extracts the appropriate service and sets the timeout. But you probably wouldn't be able to do it over IQueryable, since at that point the DbSet is already buried inside the expression tree and not very accessible. |
We are trying to migrate ef core 7 from NHibernate. Consider allow us to specify custom timeouts for specific linq statements.
Suggested extension methods could be like below.
"context.Set().WithQueryTimeout(100)"
Is there any way to specify timeout(in seconds) through linq not "context.Database" property.
The text was updated successfully, but these errors were encountered: