c# - Asynchronous LINQ -


i looking async .where() not find 1 after research i've created one.

public static class linqextension {     public static async task<ienumerable<t>> whereasync<t>(this ienumerable<t> source, func<t, task<bool>> @delegate)     {         var tasks = source.select(async t => new         {             predicate = await @delegate(t).configureawait(false),             value = t         }).tolist();          var results = await task.whenall(tasks).configureawait(false);          ienumerable<t> typelist = results.where(pred => pred.predicate).select(val => val.value);         return typelist;     } } 

when try use runtime error

cannot convert implicit type bool task , yes it's correct

this how i've tried

var q = await context.stockhistories.whereasync(x => x.productid == productid); 

i've tried

context.stockhistories.whereasync(task.run(() => { x => x.productid == productid; })); 

but getting

only assignment, call, increment, decrement, , new object expressions can used statement

can please provide solution , explain doing wrong?

the async methods ef ones execute query. want is

var q = await context.stockhistories.where(x => x.productid == productid).tolistasync(); 

basically there isn't asynchronous where method because doesn't make sense have 1 because it's used generate actual sql executed on db. query isn't run until iterate results, , methods have asynchronous version.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -