c# - Internal Server error when using ToListAsync() or CountAsync() -


i using code return list of objects in api:

 [httpget("/api/product")] public async task<queryresultresource<positionresource>> getproducts(jobqueryresource queryobjresource) {     var jobs = await context.job.tolistasync();      var projects = await context.project.tolistasync();      var volunteerships = await context.volunteership.tolistasync();      var internships = await context.internship.tolistasync();      var products1 = mapper.map<ienumerable<job>, ienumerable<positionresource>>(jobs);     foreach (var p in products1)         p.producttype = "job";      var products2 = mapper.map<ienumerable<project>, ienumerable<positionresource>>(projects);     foreach (var p in products2)         p.producttype = "project";      var products3 = mapper.map<ienumerable<volunteership>, ienumerable<positionresource>>(volunteerships);     foreach (var p in products3)         p.producttype = "volunteership";      var products4 = mapper.map<ienumerable<internship>, ienumerable<positionresource>>(internships);     foreach (var p in products4)         p.producttype = "internship";      var products = products1.concat(products2).concat(products3).concat(products4).asqueryable();     products = products.orderbydescending(x => x.creationdate);     products = products.where(x => x.isactive == true).asqueryable();       var queryobj = mapper.map<jobqueryresource, jobquery>(queryobjresource);      var result = new queryresult<positionresource>();       var columnsmap = new dictionary<string, expression<func<positionresource, object>>>()     {         ["title"] = j => j.title,         ["city"] = j => j.city,         ["type"] = j => j.type,         ["industry"] = j => j.industry     };       products = products.applyordering(queryobj, columnsmap).asqueryable();      result.totalitems = await products.countasync();      products = products.applypaging(queryobj);      result.items = await products.tolistasync();      return mapper.map<queryresult<positionresource>, queryresultresource<positionresource>>(result);  } 

i`m getting internal server error. removed await keyword , used count() , tolist()

 result.totalitems = await products.countasync(); ... result.items = await products.tolistasync(); 

it worked no errors , don`t understand why.

maybe 1 of steps before generating problem?


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -