s
o
u
l
s
j
i
e

SqlSugar数据库辅助类

using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyMS
{
    /// <summary>
    /// 数据库辅助类-生成实体、创建数据库对象
    /// </summary>
    public class DBHelp
    {
        /// <summary>
        /// 数据库对象
        /// </summary>
        public static SqlSugarClient db = null;

        /// <summary>
        /// 创建数据库连接对象
        /// </summary>
        /// <returns></returns>
        public static void InitDB()
        {
            ConnectionConfig connectionConfig = new ConnectionConfig()
            {
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true,
                ConnectionString = "Data Source=localhost;Initial Catalog=MYMS;User Id=sa;Password=123!@#"
            };
            db = new SqlSugarClient(connectionConfig);
        }

        /// <summary>
        /// 创建数据库实体
        /// </summary>
        public static void CreateModel()
        {
            if (db != null)
            {
                db.DbFirst.IsCreateAttribute().CreateClassFile("D:\\", "Models");
            }
        }
    }
}

  

posted @ 2022-12-08 14:24  soulsjie  阅读(315)  评论(0编辑  收藏  举报
你累吗?累就对了,当你觉得累时证明你在走上坡路!-----NotFoundObject - 2016-12-14 08:43