简体   繁体   中英

Entity framework core (with mysql) model first apporach how to run custom query to get some count

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);
    }
       

https://docs.microsoft.com/en-us/aspnet/web-api/overview/data/using-web-api-with-entity-framework/part-5

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM