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 });
            }
        }
    }
}
相关推荐
qq_3564086621 分钟前
es通过分片迁移迁移解决磁盘不均匀问题
java·数据库·elasticsearch
武子康43 分钟前
Java-122 深入浅出 MySQL CAP理论详解与分布式事务实践:从2PC到3PC与XA模式
java·大数据·数据库·分布式·mysql·性能优化·系统架构
爱考证的小刘1 小时前
阿里云ACA认证[特殊字符]阿里云ACP认证
数据库·阿里云·云计算
Databend1 小时前
基于 Databend 的实时数据汇聚平台建设
数据库
玄尺_0071 小时前
bug:uniCloud报Business Failed, 参数有误retry invoke error
数据库·bug
@CLoudbays_Martin111 小时前
CDN是否能有效检测并且同时防御Ddos 和 CC 攻击?
java·服务器·网络·数据库·git·数据库开发·时序数据库
爱喝水的鱼丶2 小时前
SAP-MM:SAP采购组织全面学习指南:从概念到实战配置图解
运维·开发语言·数据库·学习·sap·mm模块·采购组织
深鱼~2 小时前
DbGate数据库管理新方案:cpolar打造跨平台远程访问通道
数据库
WAWA战士3 小时前
mysql总结
数据库
朱自清的诗.3 小时前
使用python脚本储存mosquito服务器数据到sqlite
python·单片机·sqlite·esp32