Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a .net core API which has a controller named PowerBoxCircuitCurrent


[HttpGet]
public IActionResult Get()
{
var res = db.PowerBoxCircuitCurrents.ToList();
return Ok(res);
}


Here PowerBoxCircuitCurrents is a service

What I have tried:

I tried dapper.queriesAsync but it's not working
Posted
Updated 30-Apr-22 0:00am

Should be as simple as:
C#
[HttpGet]
public async Task<IActionResult> Get()
{
  // Here you will need to replace the function call with
  // one which is async and produces a list or enumerable
  // As you said in your question that will probably be
  // QueryAsync()
  var res = await db.PowerBox.CircuitCurrents.X();
  return Ok(res);
}
 
Share this answer
 

Just add the ToListAsync extension to your database call and change the Get method signature to so that it can await the returned value.


C#
public async Task<IActionResult> Get()
       {
         var myList= await db.PowerBox.CircuitCurrents.X().ToListAsync();
         return new JsonResult(new { data = myList });//serialise the list to json
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900