From 8b99025d0dad17106bcc10b98df3e8e8c5904308 Mon Sep 17 00:00:00 2001 From: skx <610262374@qq.com> Date: Tue, 10 Nov 2020 22:34:01 +0800 Subject: [PATCH] Update CodeFirst --- .../SqlServerTest/SqlServerTest.csproj | 3 +- .../_OldTest/BugTest/{Bug3t.cs => Bug3.cs} | 0 .../SqlServerTest/_OldTest/BugTest/Bug5.cs | 128 ++++++++++++++++++ .../CodeFirstProvider/CodeFirstProvider.cs | 3 + 4 files changed, 133 insertions(+), 1 deletion(-) rename Src/Asp.Net/SqlServerTest/_OldTest/BugTest/{Bug3t.cs => Bug3.cs} (100%) create mode 100644 Src/Asp.Net/SqlServerTest/_OldTest/BugTest/Bug5.cs diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj index 213e7351f..d47e04b6c 100644 --- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj +++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj @@ -79,6 +79,7 @@ + @@ -93,7 +94,7 @@ - + diff --git a/Src/Asp.Net/SqlServerTest/_OldTest/BugTest/Bug3t.cs b/Src/Asp.Net/SqlServerTest/_OldTest/BugTest/Bug3.cs similarity index 100% rename from Src/Asp.Net/SqlServerTest/_OldTest/BugTest/Bug3t.cs rename to Src/Asp.Net/SqlServerTest/_OldTest/BugTest/Bug3.cs diff --git a/Src/Asp.Net/SqlServerTest/_OldTest/BugTest/Bug5.cs b/Src/Asp.Net/SqlServerTest/_OldTest/BugTest/Bug5.cs new file mode 100644 index 000000000..bf7ddddc2 --- /dev/null +++ b/Src/Asp.Net/SqlServerTest/_OldTest/BugTest/Bug5.cs @@ -0,0 +1,128 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest.Test +{ + public class BugTest5 + { + public static void Init() + { + SqlSugarClient Db = new SqlSugarClient(new ConnectionConfig() + { + ConnectionString = Config.ConnectionString, + DbType = DbType.SqlServer, + IsAutoCloseConnection = true, + //MoreSettings = new ConnMoreSettings() + //{ + // PgSqlIsAutoToLower = true //我们这里需要设置为false + //}, + InitKeyType = InitKeyType.Attribute, + }); + //调式代码 用来打印SQL + Db.Aop.OnLogExecuting = (sql, pars) => + { + Console.WriteLine(sql); + }; + + Db.CodeFirst.InitTables(typeof(Base_MenuList)); + Db.CodeFirst.InitTables(typeof(aaaa)); + Db.CodeFirst.InitTables(typeof(bbbbb)); + + } + [SugarTable("xxxx.Base_MenuList")] + + public class Base_MenuList + + { + + /// + + /// 菜单主键Id + + /// + + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "菜单主键Id")] + + public int MenuID { get; set; } + + + + /// + + /// 名称 + + /// + + [SugarColumn(IsNullable = false, Length = 50, ColumnDescription = "名称")] + + public string MenuName { get; set; } + + } + + [SugarTable("xxxx1x")] + + public class aaaa + + { + + /// + + /// 菜单主键Id + + /// + + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "菜单主键Id")] + + public int MenuID { get; set; } + + + + /// + + /// 名称 + + /// + + [SugarColumn(IsNullable = false, Length = 50, ColumnDescription = "名称")] + + public string MenuName { get; set; } + + } + [SugarTable("bbbbb")] + + public class bbbbb + + { + + /// + + /// 菜单主键Id + + /// + + [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "菜单主键Id")] + + public int MenuID { get; set; } + + + + /// + + /// 名称 + + /// + + [SugarColumn(IsNullable = false, Length = 50, ColumnDescription = "名称")] + + public string MenuName { get; set; } + + } + } + + +} diff --git a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs index 2f3273758..39a4cfaf4 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs @@ -109,6 +109,9 @@ namespace SqlSugar } } var tableName = GetTableName(entityInfo); + this.Context.MappingTables.Add(entityInfo.EntityName,tableName); + entityInfo.DbTableName = tableName; + entityInfo.Columns.ForEach(it => { it.DbTableName = tableName; }); var isAny = this.Context.DbMaintenance.IsAnyTable(tableName); if (isAny) ExistLogic(entityInfo);