[英]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.我在我的存储库中使用实体框架核心获取不同的模型 get/add/update/delete 和 getall 现在对于一个场景,我需要纠正自定义查询以获取计数。 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.创建数据传输对象 (DTO) 例如。
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 https://docs.microsoft.com/en-us/aspnet/web-api/overview/data/using-web-api-with-entity-framework/part-5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.