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 });
            }
        }
    }
}
相关推荐
高铭杰27 分钟前
mysql主备配置(对比postgresql)
数据库·mysql·replication
~~李木子~~5 小时前
MySQL 迁移总结报告
数据库·mysql
有梦想的攻城狮7 小时前
通过Lettuce实现PB3格式对象在Redis中的存储与查询
数据库·redis·缓存·pb3
CodeLongBear7 小时前
MySQL索引篇 -- 从数据页的角度看B+树
mysql·面试
桦07 小时前
MySQL【函数】
数据库·mysql
⑩-7 小时前
Redis(1)
数据库·redis·缓存
2301_803554528 小时前
主从同步配置的步骤
数据库
无敌最俊朗@8 小时前
00-7天攻破sqlite数据库(总览sqlite)
数据库·sqlite
Access开发易登软件8 小时前
Access导出带图表的 HTML 报表:技术实现详解
数据库·后端·html·vba·导出·access
_Minato_8 小时前
数据库知识整理——SQL数据定义
数据库·sql·mysql·oracle·database·数据库开发·数据库架构