net8.0一键创建支持(Orm-Sqlite-MySql-SqlServer)

Necore项目生成器 - 在线创建Necore模板项目 | 一键下载

DbController.cs

cs 复制代码
using Dm;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.DirectoryServices.Protocols;
using UnT.Template.Application.Responses;
using UnT.Template.Domain;

namespace UnT.Template.Controllers
{
    [Route("api/dbs")]
    [ApiController]
    public class DbController : ControllerBase
    {
        private readonly ISqlSugarClient _sqlSugarClient;

        public DbController(ISqlSugarClient sqlSugarClient)
        {
            _sqlSugarClient = sqlSugarClient;
        }

        [HttpPost("insert")]
        [Produces("application/json")]
        [ProducesResponseType(typeof(ApiResponse<bool>), StatusCodes.Status200OK)] 
        public IActionResult Insert()
        {
            try
            {
                _sqlSugarClient.Insertable(new Pro_Product { Name = DateTime.Now.ToFileTime().ToString() }).ExecuteCommand();
                return Ok(new ApiResponse<bool> { Success = true, Data = true });
            }
            catch (Exception ex)
            {
                return Ok(new ApiResponse<bool> { Success = false, Message = ex.Message, Data = false });
            }
        }

        [HttpPost("count")]
        [Produces("application/json")]
        [ProducesResponseType(typeof(ApiResponse<int>), StatusCodes.Status200OK)]
        public IActionResult Count()
        {
            try
            {
                var count = _sqlSugarClient.Queryable<Pro_Product>().Count();
                return Ok(new ApiResponse<int> { Success = true, Data = count });
            }
            catch (Exception ex)
            {
                return Ok(new ApiResponse<int> { Success = false, Message = ex.Message });
            }
        }
    }
}
相关推荐
绘梨衣5474 分钟前
Docker+FastAPI+MySQL 项目部署报错汇总
mysql·docker·fastapi
小江的记录本12 分钟前
【Kafka核心】架构模型:Producer、Broker、Consumer、Consumer Group、Topic、Partition、Replica
java·数据库·分布式·后端·搜索引擎·架构·kafka
dvjr cloi17 分钟前
MySQL Workbench菜单汉化为中文
android·数据库·mysql
dFObBIMmai1 小时前
MySQL主从同步中大事务导致的延迟_如何拆分大事务优化同步
jvm·数据库·python
szccyw01 小时前
mysql如何限制特定存储过程执行权限_MySQL存储过程安全访问
jvm·数据库·python
czlczl200209251 小时前
利用“延迟关联”优化 MySQL 巨量数据的深分页查询
数据库·mysql
ACP广源盛139246256732 小时前
IX8024与科学大模型的碰撞@ACP#筑牢科研 AI 算力高速枢纽分享
运维·服务器·网络·数据库·人工智能·嵌入式硬件·电脑
Elastic 中国社区官方博客2 小时前
ES|QL METRICS_INFO 和 TS_INFO:为你的时间序列数据建立目录
大数据·数据库·elasticsearch·搜索引擎·信息可视化·全文检索
俺不要写代码2 小时前
数据库:函数
数据库·mysql
2401_882273722 小时前
如何在 CSS 中正确加载本地 JPG 背景图片
jvm·数据库·python