| | |
| | | using Castle.Components.DictionaryAdapter.Xml; |
| | | using Microsoft.AspNetCore.Mvc.Rendering; |
| | | using Newtonsoft.Json; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using SkiaSharp; |
| | | using SqlSugar; |
| | | using System; |
| | |
| | | // 注意不要把其他命名空间下的也添加进来。 |
| | | Console.WriteLine("Create Tables..."); |
| | | |
| | | var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory; |
| | | var referencedAssemblies = System.IO.Directory.GetFiles(path, MainDb.AssemblyName).Select(Assembly.LoadFrom).ToArray(); |
| | | string path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory; |
| | | Assembly[] referencedAssemblies = System.IO.Directory.GetFiles(path, MainDb.AssemblyName).Select(Assembly.LoadFrom).ToArray(); |
| | | |
| | | var modelTypes = referencedAssemblies |
| | | List<Type> modelTypes = referencedAssemblies |
| | | .SelectMany(a => a.DefinedTypes) |
| | | .Select(type => type.AsType()) |
| | | .Where(x => x.IsClass && x.Namespace is MainDb.EntityNameSpace && x.GetCustomAttribute<SugarTable>() != null) |
| | |
| | | { |
| | | PropertyInfo propertyInfo = propertyInfos[i]; |
| | | |
| | | SequenceAttirbute? sequenceAttirbute = propertyInfo.GetCustomAttribute<SequenceAttirbute>(); |
| | | SequenceAttribute? sequenceAttirbute = propertyInfo.GetCustomAttribute<SequenceAttribute>(); |
| | | if (sequenceAttirbute != null) |
| | | { |
| | | int count = dbContext.Db.Ado.GetScalar($"SELECT COUNT(*) FROM sys.sequences WHERE name = '{sequenceAttirbute.SequenceName}'").ObjToInt(); |
| | |
| | | else |
| | | dic[i].Add("CreateDate", DateTime.Now); |
| | | } |
| | | string str = $"SET IDENTITY_INSERT {t.Name} ON;"; |
| | | string str = ""; |
| | | if (DBContext.DbType == SqlSugar.DbType.SqlServer) |
| | | { |
| | | str += $"SET IDENTITY_INSERT {t.Name} ON;"; |
| | | |
| | | str += dbContext.Db.Insertable(dic).AS(t.Name).ToSqlString(); |
| | | str += dbContext.Db.Insertable(dic).AS(t.Name).ToSqlString(); |
| | | |
| | | str += ($"SET IDENTITY_INSERT {t.Name} OFF;"); |
| | | str += ($"SET IDENTITY_INSERT {t.Name} OFF;"); |
| | | |
| | | dbContext.Db.Ado.ExecuteCommand(str); |
| | | dbContext.Db.Ado.ExecuteCommand(str); |
| | | } |
| | | else |
| | | { |
| | | dbContext.Db.Insertable(dic).AS(t.Name).ExecuteCommand(); |
| | | } |
| | | |
| | | ConsoleHelper.WriteSuccessLine($"Table [{t.Name}] SeedData Added Successfully"); |
| | | } |
| | |
| | | { |
| | | PropertyInfo propertyInfo = propertyInfos[i]; |
| | | |
| | | SequenceAttirbute? sequenceAttirbute = propertyInfo.GetCustomAttribute<SequenceAttirbute>(); |
| | | SequenceAttribute? sequenceAttirbute = propertyInfo.GetCustomAttribute<SequenceAttribute>(); |
| | | if (sequenceAttirbute != null) |
| | | { |
| | | int count = dbContext.Db.Ado.GetScalar($"SELECT COUNT(*) FROM sys.sequences WHERE name = '{sequenceAttirbute.SequenceName}'").ObjToInt(); |
| | | if (count == 0) |
| | | { |
| | | string sql = $"CREATE SEQUENCE {sequenceAttirbute.SequenceName} AS [int] START WITH {sequenceAttirbute.StartWith} INCREMENT BY {sequenceAttirbute.Increment} MINVALUE {sequenceAttirbute.SeqMinValue} MAXVALUE {sequenceAttirbute.SeqMaxValue} {(sequenceAttirbute.IsCycle ? "CYCLE" : "")} CACHE"; |
| | | int count = dbContext.Db.Ado.GetScalar($"SELECT COUNT(*) FROM sys.sequences WHERE name = '{sequenceAttirbute.SequenceName}'").ObjToInt(); |
| | | if (count == 0) |
| | | { |
| | | string sql = $"CREATE SEQUENCE {sequenceAttirbute.SequenceName} AS [int] START WITH {sequenceAttirbute.StartWith} INCREMENT BY {sequenceAttirbute.Increment} MINVALUE {sequenceAttirbute.SeqMinValue} MAXVALUE {sequenceAttirbute.SeqMaxValue} {(sequenceAttirbute.IsCycle ? "CYCLE" : "")} CACHE"; |
| | | dbContext.Db.Ado.ExecuteCommand(sql); |
| | | } |
| | | } |
| | | } |
| | | SugarColumn? sugarColumn = propertyInfo.GetCustomAttribute<SugarColumn>(); |
| | | if (sugarColumn != null) |