簡體   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