I am using entity framework core in my repository get different model get/add/update/delete and getall Now for one scenario i need to right a custom query to get count. I am unable to found any method where i can run the custom query. Have any body used it.
Create Data Transfer Objects (DTOs) eg.
public class yourclassname
{
public string yourfiledname { get; set; }
public int count { get; set; }
}
then you
public IActionResult gettop10staffcount()
{
var query = "your query";
var result = Context.yourclassname.FromSql(query).ToList();
return new ObjectResult(result);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.