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 });
            }
        }
    }
}
相关推荐
程序猿乐锅4 分钟前
【MySQL | 第七篇】 索引使用规则
数据库·sql·mysql
C137的本贾尼12 分钟前
崩溃恢复揭秘:从 Redo Log 到数据一致性
数据库
Lyyaoo.12 分钟前
【MySQL】锁机制
android·数据库·mysql
文中金域18 分钟前
备份sqlite数据库
数据库·sqlite
摇滚侠20 分钟前
Maven 入门+高深 SSM 案例 111-112
java·数据库·maven
ZengLiangYi34 分钟前
从 RAG 到知识图谱:个人知识管理的演进
数据库·后端·程序员
zuYM4g7Dp40 分钟前
文顶顶iOS开发数据库篇—SQL
数据库·sql·ios
WyCAGy8ij40 分钟前
Redis 分布式锁进阶第四篇讲解
数据库·redis·分布式
锋行天下1 小时前
中小项目高可用,真的需要K8s吗?从单机备份到企业级架构的完整思考
后端·mysql·nginx
tedcloud1231 小时前
FluentFlyout部署教程:打造更美观的Windows桌面环境
数据库·人工智能·sql·学习·自动化