繁体   English   中英

实体框架核心(带有 mysql)模型首先接近如何运行自定义查询以获取一些计数

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

我在我的存储库中使用实体框架核心获取不同的模型 get/add/update/delete 和 getall 现在对于一个场景,我需要纠正自定义查询以获取计数。 我找不到任何可以运行自定义查询的方法。 有任何身体使用过它。

创建数据传输对象 (DTO) 例如。

 public class yourclassname
    {
        public string yourfiledname { get; set; }
        public int count { get; set; }
    }

那么你

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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