简体   繁体   English

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

[英]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.

相关问题 如何使用 C# 中的数据库优先方法生成具有所有 CRUD 操作的存储库和模型/实体类 - how to generate the Repository and model/entity classes with all CRUD operations using database-first apporach in C# 如何使用复合键在 model 的实体框架核心中获取单个实体? - How to get single entity in Entity Framework Core of model with composite key? 如何从C#Entity Framework Code First Model获取mysql char列类型 - How to get mysql char column type from C# Entity Framework Code First Model 如何使用 Entity Framework Core 5 中的自定义列进行 SQL 查询 - How to make an SQL query with custom columns in Entity Framework Core 5 Dapper:如何在 Entity Framework Core 中获取查询结果的值 - Dapper: How to get value of query result in Entity Framework Core 实体框架(EF6)+ MySql数据库优先模型多对多关系错误查询生成 - Entity Framework (EF6) + MySql Database First Model Many to Many Relationship Wrong Query Generation Entity Framework Core 首次查询与后续查询性能 - Entity Framework Core first query vs subsequent query performance Entity Framework Core 3 - 带有来自存储过程的一些字段的模型 - Entity Framework Core 3 - model with some fields from a stored procedure Entity Framework Core Database 首先不渲染存储过程的Model? - Entity Framework Core Database First not render Model of Stored Procedure? 如何让这个实体框架 SQL 查询正常运行 - How get this Entity Framework SQL Query to run properly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM