c# - Multiple queries in async/await (Error: IEnumerable does not contain ToListAsync()) -


i share went through other similar posts suggested solutions din't work me , that's why creating separate thread.i trying join 2 results using asynchronous programming in entity framework.i have 3 methods below:

the method preprocessappointment() waits on other 2 methods getappttask() , getzonetask()

public async void preprocessappointment()         {             var task_1 = getappttask();             var task_2 = getzonetask();             await task.whenall(task_1, task_2);         } 

the method getappttask() not give error.

public async task<ienumerable<appointments>> getappttask(){              var result = db.appointments.where(d => d.appt_client_id == 15 && d.customer_id == 68009);              return await result.tolistasync();           } 

the method getzonetask()gives following error. ienumerable <zones> not contain definition tolistasync().

public async task <ienumerable<zones>> getzonetask()         {             var result = db.zones.where(d => d.zone_client_id == "15").asenumerable().distinct<zones>(new zones.comparer());             return await result.tolistasync();         } 

i unable find out might causing error.i attaching models structures appointments , zones below. difference between models apart fields definition of comparer class in zones.

zones.cs

public class zones     {         [column(order=0),key]         [stringlength(50)]         public string zone_client_id { get; set; }         //public int zone_client_id { get; set; }          [column(order = 1), key]         [stringlength(5)]         public string zip { get; set; }           [stringlength(50)]         public string zone { get; set; }          public class comparer : iequalitycomparer<zones>         {             public bool equals(zones x, zones y)             {                 return x.zone_client_id == y.zone_client_id                      && x.zip == y.zip                      && x.zone == y.zone;             }              public int gethashcode(zones obj)             {                 return obj.zone_client_id.gethashcode() ^                       obj.zip.gethashcode() ^                       obj.zone.gethashcode();                }         }     } 

appointments.cs

 public  partial class appointments     {          public int appt_client_id { get; set; }          public int customer_id { get; set; }          [key]         public int appt_id { get; set; }          public datetime appt_date_time { get; set; }          [stringlength(200)]         public string recording_uri { get; set; }          public datetime time_stamp { get; set; }          [required]         [stringlength(20)]         public string appt_status { get; set; }          [required]         [stringlength(5)]         public string appt_type { get; set; } } 

tolistasync() works on iqueryable<t> only, when turned in ienumerable<t> via asenumerable() lost ability call it.

because once asenumerable() working in memory collection anyway, make list @ point.

var allzones = await db.zones.where(d => d.zone_client_id == "15").tolistasync().configureawait(false); return allzones.distinct<zones>(new zones.comparer()).tolist(); 

the last .tolist() optional. if don't , enumerate returned ienumerable multiple times run distinct multiple times. doing .tolist() makes "remembers" result of distinct instead of re-calculating it.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

http - Safari render HTML as received -