c# - 实体框架核心(使用 mysql)模型首先 apporach 如何运行自定义查询以获得一些计数
问题描述
我在我的存储库中使用实体框架核心获取不同的模型 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);
}
推荐阅读
- c# - 如何使变量只能在 C# 中设置一次?
- windows - 移动文件批处理不能通过双击工作,但可以从命令行工作
- arduino - 串行命令后保持 LED 亮起
- php - sql查询太慢
- javascript - 在 ReactJS 中定义函数时,仅在括号中使用括号和花括号有什么区别?
- javascript - 如何修复套接字 io 中的 400 错误错误请求?
- c++ - 无法生成 Mandelbrot 矩阵以将其保存到 C++ 线程中的文件
- c# - 我无法反序列化我的 json api 上的可变属性日期
- java - 需要从文件中获取一行到队列中,而不是整个文件文本
- rest - 套接字可以代替 HTTP 请求吗?(套接字与 http)