From e91f9c8456b3a3e7f95af09b0646be99555305a7 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 21 Jan 2019 01:01:38 +0800 Subject: [PATCH] Update Demo --- .../SugarCodeGeneration/Codes/DbContextParameter.cs | 1 + Src/Asp.Net/SugarCodeGeneration/Program.cs | 7 ++++--- Src/Asp.Net/SugarCodeGeneration/Template/DbContext.txt | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Src/Asp.Net/SugarCodeGeneration/Codes/DbContextParameter.cs b/Src/Asp.Net/SugarCodeGeneration/Codes/DbContextParameter.cs index 0bee0bed1..762edb29d 100644 --- a/Src/Asp.Net/SugarCodeGeneration/Codes/DbContextParameter.cs +++ b/Src/Asp.Net/SugarCodeGeneration/Codes/DbContextParameter.cs @@ -8,5 +8,6 @@ namespace SugarCodeGeneration public string ConnectionString { get; set; } public DbType DbType { get; set; } public List Tables { get; set; } + public string ClassNamespace { get; set; } } } \ No newline at end of file diff --git a/Src/Asp.Net/SugarCodeGeneration/Program.cs b/Src/Asp.Net/SugarCodeGeneration/Program.cs index 8c274c68e..b0ea30821 100644 --- a/Src/Asp.Net/SugarCodeGeneration/Program.cs +++ b/Src/Asp.Net/SugarCodeGeneration/Program.cs @@ -45,7 +45,7 @@ namespace SugarCodeGeneration var savePath = Methods.GetSlnPath + "\\" + contextProjectName + "\\" + contextPath + "\\DbContext.cs";//具体文件名 var tables = db.DbMaintenance.GetTableInfoList().Select(it => it.Name).ToList(); //执行生成 - GenerationDContext(contextProjectName, contextPath, savePath, tables); + GenerationDContext(contextProjectName, contextPath, savePath, tables, classNamespace); Print("DbContext创建成功"); @@ -96,14 +96,15 @@ namespace SugarCodeGeneration /// /// 生成DbContext /// - private static void GenerationDContext(string contextProjectName, string contextPath, string savePath,List tables) + private static void GenerationDContext(string contextProjectName, string contextPath, string savePath,List tables,string classNamespace) { var templatePath = Methods.GetCurrentProjectPath + "\\Template\\DbContext.txt";//dbcontexts模版文件 //下面代码不动 var model = new DbContextParameter{ ConnectionString = connectionString, DbType = dbType, - Tables = tables + Tables = tables, + ClassNamespace= classNamespace }; Methods.CreateDbContext(templatePath,savePath,model); AddTask(contextProjectName,contextPath); diff --git a/Src/Asp.Net/SugarCodeGeneration/Template/DbContext.txt b/Src/Asp.Net/SugarCodeGeneration/Template/DbContext.txt index c2fe1c574..75bab6c27 100644 --- a/Src/Asp.Net/SugarCodeGeneration/Template/DbContext.txt +++ b/Src/Asp.Net/SugarCodeGeneration/Template/DbContext.txt @@ -1,4 +1,4 @@ -using MyTest; +using @Model.ClassNamespace; using SqlSugar; using System; using System.Collections.Generic;