using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Waste.CreateDB { public class CreateTable { public SqlSugarClient Db; public CreateTable() { Db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = "Server=123.60.2.99,4331;Database=waste;uid=jutian_user;pwd=jutian1qaz@WSX;", DbType = DbType.SqlServer,//设置数据库类型 IsAutoCloseConnection = true,//自动释放数据库,如果存在事务,在事务结束之后释放。 InitKeyType = InitKeyType.Attribute//从实体特性中读取主键自增列信息 }); Db.Aop.OnLogExecuting = (sql, pars) => { Console.WriteLine(sql + "\r\n" + Db.Utilities.SerializeObject (pars.ToDictionary(it => it.ParameterName, it => it.Value))); Console.WriteLine(); }; } public void Create(bool Backup = false, int StringDefaultLength = 50, params Type[] types) { // Db.CodeFirst.SetStringDefaultLength(StringDefaultLength); Db.DbMaintenance.CreateDatabase(); if (Backup) { Db.CodeFirst.BackupTable().InitTables(types); } else { Db.CodeFirst.InitTables(types); } } } }