From 17e4c7e3e7b3ef60d9da6de3b2a39a14a53c38a0 Mon Sep 17 00:00:00 2001
From: z8018 <1282578289@qq.com>
Date: 星期三, 12 三月 2025 14:11:33 +0800
Subject: [PATCH] 1

---
 WIDESEAWCS_Server/WIDESEAWCS_Core/Seed/DBSeed.cs |   33 +++++++++++++++++++++------------
 1 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Core/Seed/DBSeed.cs b/WIDESEAWCS_Server/WIDESEAWCS_Core/Seed/DBSeed.cs
index 94924fa..81b60b4 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_Core/Seed/DBSeed.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_Core/Seed/DBSeed.cs
@@ -1,6 +1,7 @@
 锘縰sing Castle.Components.DictionaryAdapter.Xml;
 using Microsoft.AspNetCore.Mvc.Rendering;
 using Newtonsoft.Json;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
 using SkiaSharp;
 using SqlSugar;
 using System;
@@ -66,10 +67,10 @@
                 // 娉ㄦ剰涓嶈鎶婂叾浠栧懡鍚嶇┖闂翠笅鐨勪篃娣诲姞杩涙潵銆�
                 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)
@@ -140,13 +141,21 @@
                                         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");
                                 }
@@ -168,12 +177,12 @@
                                 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)

--
Gitblit v1.9.3