From 8abaf48a121c71015faac4cc960969aeceed1020 Mon Sep 17 00:00:00 2001 From: skx <610262374@qq.com> Date: Tue, 13 Oct 2020 10:37:48 +0800 Subject: [PATCH] Mapper BUG --- Src/Asp.Net/PgSqlTest/Bugs/BugTest.cs | 227 ++++++++++++++++++ Src/Asp.Net/PgSqlTest/Demo/DemoD_DbFirst.cs | 5 +- Src/Asp.Net/PgSqlTest/PgSqlTest.csproj | 1 + .../QueryableProvider/QueryableProvider.cs | 2 +- 4 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 Src/Asp.Net/PgSqlTest/Bugs/BugTest.cs diff --git a/Src/Asp.Net/PgSqlTest/Bugs/BugTest.cs b/Src/Asp.Net/PgSqlTest/Bugs/BugTest.cs new file mode 100644 index 000000000..83e110f47 --- /dev/null +++ b/Src/Asp.Net/PgSqlTest/Bugs/BugTest.cs @@ -0,0 +1,227 @@ +//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 BugTest +// { +// public static void Init() +// { +// SqlSugarClient Db = new SqlSugarClient(new ConnectionConfig() +// { +// ConnectionString = @"PORT=5433;DATABASE=x;HOST=localhost;PASSWORD=haosql;USER ID=postgres", +// DbType = DbType.PostgreSQL, +// IsAutoCloseConnection = true, +// //MoreSettings = new ConnMoreSettings() +// //{ +// // PgSqlIsAutoToLower = true //我们这里需要设置为false +// //}, +// InitKeyType = InitKeyType.Attribute, +// }); +// //调式代码 用来打印SQL +// Db.Aop.OnLogExecuting = (sql, pars) => +// { +// // Debug.WriteLine(sql); +// }; + +// var 查询成功 = Db.Queryable() +// .Where(x => x.Enable == true) //不加 ture ,也会出错 +// .ToList(); + + +// var Dbfirst情况使用Mapper_Menu_Id为大写自动转成小写 = Db.Queryable() +// .Where(x => x.Enable == true) +// .Mapper(x => x.orderList, x => x.Menu_Id) //初始化数据库失败42703: 字段 "menu_id" 不存在 +// .ToList(); +// } +// } +// public class Sys_RoleAuth +// { +// /// +// /// +// /// +// [Key] +// [Display(Name = "")] +// [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] +// public int Auth_Id { get; set; } + +// /// +// /// +// /// +// [Display(Name = "")] +// public int Role_Id { get; set; } + +// /// +// /// +// /// +// [Display(Name = "")] +// public int User_Id { get; set; } + +// /// +// /// +// /// +// [Display(Name = "")] +// [SugarColumn(IsNullable = false)] +// public int Menu_Id { get; set; } + +// /// +// ///用户权限 +// /// +// [Display(Name = "用户权限")] +// [SugarColumn(IsNullable = false, IsJson = true, ColumnDataType = "json")] +// public List AuthValue { get; set; } = new List(); + +// /// +// /// +// /// +// [Display(Name = "")] +// [MaxLength(100)] +// public string Creator { get; set; } + +// /// +// /// +// /// +// [Display(Name = "")] +// public DateTime CreateDate { get; set; } + +// /// +// /// +// /// +// [Display(Name = "")] +// [MaxLength(100)] +// public string Modifier { get; set; } + +// /// +// /// +// /// +// [Display(Name = "")] +// public DateTime ModifyDate { get; set; } +// } +// public class Sys_Actions +// { +// public int Action_Id { get; set; } +// public int Menu_Id { get; set; } +// public string Text { get; set; } +// public string Value { get; set; } +// } +// public class Sys_Menu +// { +// /// +// ///ID +// /// +// [Key] +// [Display(Name = "ID")] +// [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] +// public int Menu_Id { get; set; } + +// /// +// ///父级ID +// /// +// [Display(Name = "父级ID")] +// [SugarColumn(IsNullable = false)] +// public int ParentId { get; set; } + + +// /// +// ///菜单名称 +// /// +// [Display(Name = "菜单名称")] +// [MaxLength(50)] +// [SugarColumn(IsNullable = false)] +// public string MenuName { get; set; } + +// /// +// /// +// /// +// [Display(Name = "TableName")] +// [MaxLength(200)] +// public string TableName { get; set; } + +// /// +// /// +// /// +// [Display(Name = "Url")] +// [MaxLength(10000)] +// public string Url { get; set; } + +// /// +// ///权限 +// /// +// [Display(Name = "权限")] +// [MaxLength(-1)] +// [SugarColumn(IsNullable = false, IsJson = true, ColumnDataType = "json")] +// public List Auth { get; set; } = new List(); + +// /// +// /// +// /// +// [Display(Name = "Description")] +// [MaxLength(200)] +// public string Description { get; set; } + + +// /// +// ///图标 +// /// +// [Display(Name = "图标")] +// [MaxLength(50)] +// public string Icon { get; set; } + +// /// +// ///排序号 +// /// +// [Display(Name = "排序号")] +// public int OrderNo { get; set; } + +// /// +// ///创建人 +// /// +// [Display(Name = "创建人")] +// [MaxLength(50)] +// public string Creator { get; set; } + +// /// +// ///创建时间 +// /// +// [Display(Name = "创建时间")] +// public DateTime? CreateDate { get; set; } = DateTime.Now; + +// /// +// /// +// /// +// [Display(Name = "Modifier")] +// [MaxLength(50)] +// public string Modifier { get; set; } + +// /// +// /// +// /// +// [Display(Name = "ModifyDate")] +// public DateTime? ModifyDate { get; set; } + +// /// +// ///是否启用 +// /// +// [Display(Name = "是否启用")] +// public bool Enable { get; set; } + +// [SugarColumn(IsIgnore = true)] +// public List orderList { get; set; } +// } + +// public class Order +// { +// [Key] +// [Display(Name = "ID")] +// [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] +// public int Id { get; set; } + +// public int Menu_Id { get; set; } +// } + +//} diff --git a/Src/Asp.Net/PgSqlTest/Demo/DemoD_DbFirst.cs b/Src/Asp.Net/PgSqlTest/Demo/DemoD_DbFirst.cs index 7062f5b05..2b24db9f7 100644 --- a/Src/Asp.Net/PgSqlTest/Demo/DemoD_DbFirst.cs +++ b/Src/Asp.Net/PgSqlTest/Demo/DemoD_DbFirst.cs @@ -17,7 +17,10 @@ namespace OrmTest DbType = DbType.PostgreSQL, ConnectionString = Config.ConnectionString, InitKeyType = InitKeyType.Attribute, - IsAutoCloseConnection = true + IsAutoCloseConnection = true, + MoreSettings=new ConnMoreSettings() { + PgSqlIsAutoToLower=false + } }); db.DbFirst.CreateClassFile("c:\\Demo\\1", "Models"); diff --git a/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj b/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj index bd474a8e1..02fb506da 100644 --- a/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj +++ b/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj @@ -60,6 +60,7 @@ + diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index dcb706e37..570837252 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -1470,7 +1470,7 @@ namespace SqlSugar { new ConditionalModel() { - FieldName=whereCol.DbColumnName, + FieldName=this.SqlBuilder.GetTranslationColumnName(whereCol.DbColumnName), ConditionalType= ConditionalType.In, FieldValue=string.Join(",",inValues.Distinct()) }