diff --git a/Src/Asp.Net/PgSqlTest/Bugs/BugTest4.cs b/Src/Asp.Net/PgSqlTest/Bugs/BugTest4.cs new file mode 100644 index 000000000..b089482c1 --- /dev/null +++ b/Src/Asp.Net/PgSqlTest/Bugs/BugTest4.cs @@ -0,0 +1,46 @@ +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 BugTest4 + { + 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, + + InitKeyType = InitKeyType.Attribute, + }); + //调式代码 用来打印SQL + Db.Aop.OnLogExecuting = (sql, pars) => + { + Console.WriteLine(sql); + }; + + Db.CodeFirst.InitTables(typeof(testmmxxxmm121)); + Db.Insertable(new testmmxxxmm121() { name = (float) 0.01 , name2 = 1 }).ExecuteCommand(); + var list= Db.Queryable().ToList(); + } + } + + public class testmmxxxmm121 + { + [SugarColumn(IsPrimaryKey =true,IsIdentity =true)] + public int id { get; set; } + [SugarColumn(ColumnDataType ="float4",IsNullable =true)] + public float? name { get; set; } + [SugarColumn(ColumnDataType = "float4", IsNullable = false)] + public float? name2 { get; set; } + + } + +} diff --git a/Src/Asp.Net/PgSqlTest/Bugs/BugTest5.cs b/Src/Asp.Net/PgSqlTest/Bugs/BugTest5.cs new file mode 100644 index 000000000..9139e312e --- /dev/null +++ b/Src/Asp.Net/PgSqlTest/Bugs/BugTest5.cs @@ -0,0 +1,168 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; +namespace OrmTest.Test +{ + public class BugTest5 + + { + + [SugarTable("User")] + + public class User + + { + + [SugarColumn(IsNullable = false, ColumnDataType = "uuid", IsPrimaryKey = true)] + + public Guid Id { get; set; } + + + + /// + + /// 部门名称 + + /// + + [SugarColumn(IsNullable = false)] + + public string Name { get; set; } + + + + /// + + /// 用户部门 + + /// + + [SugarColumn(IsNullable = false, IsJson = true, ColumnDataType = "json")] + + public List UserDpt { get; set; } + + } + + + + [SugarTable("User2")] + + public class User2 + + { + + [SugarColumn(IsNullable = false, ColumnDataType = "uuid", IsPrimaryKey = true)] + + public Guid Id { get; set; } + + + + [SugarColumn(IsNullable = false, ColumnDataType = "uuid")] + + public Guid UserId { get; set; } + + } + + + + public class Department + + { + + public Guid Id { get; set; } + + public string Name { get; set; } + + } + + + + public static void Init() + + { + + SqlSugarClient db = new SqlSugarClient( + + new ConnectionConfig() + + { + + ConnectionString = Config.ConnectionString, + + DbType = DbType.PostgreSQL,//设置数据库类型 + + IsAutoCloseConnection = true,//自动释放数据务,如果存在事务,在事务结束后释放 + + InitKeyType = InitKeyType.Attribute //从实体特性中读取主键自增列信息 + + }); + + db.Aop.OnError = (exp) =>//SQL报错 + + { + + string sql = exp.Sql; + + //exp.sql 这样可以拿到错误SQL + + }; + + //db.DbMaintenance.CreateDatabase(); + + db.CodeFirst.InitTables(typeof(User), typeof(User2)); + + List departments = new List(); + + departments.Add(new Department { Id = Guid.NewGuid(), Name = "研发部" }); + + departments.Add(new Department { Id = Guid.NewGuid(), Name = "市场部" }); + + Guid userId = Guid.NewGuid(); + + User user = new User + + { + + Id = userId, + + Name = "张三", + + UserDpt = departments + + }; + + db.Insertable(user).ExecuteCommand(); + + User2 user2 = new User2(); + + user2.Id = Guid.NewGuid(); + + user2.UserId = userId; + + + + db.Insertable(user2).ExecuteCommand(); + + var data = db.Queryable((a, b) => new object[] { JoinType.Inner, a.Id == b.UserId }) + + .Where((a, b) => a.Id.ToString() == userId.ToString()) + + .Select((a, b) => new + + { + + User = a, + + Items = a.UserDpt + + }).ToList(); + + Console.ReadKey(); + + } + + } +} diff --git a/Src/Asp.Net/PgSqlTest/Config.cs b/Src/Asp.Net/PgSqlTest/Config.cs index c8c29c8d8..4f718ae16 100644 --- a/Src/Asp.Net/PgSqlTest/Config.cs +++ b/Src/Asp.Net/PgSqlTest/Config.cs @@ -16,16 +16,16 @@ namespace OrmTest /// Account have permission to create database /// 用有建库权限的数据库账号 /// - public static string ConnectionString = "PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=haosql;USER ID=postgres"; + public static string ConnectionString = "PORT=5433;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=haosql;USER ID=postgres"; /// /// Account have permission to create database /// 用有建库权限的数据库账号 /// - public static string ConnectionString2 = "PORT=5432;DATABASE=SqlSugar4xTest2;HOST=localhost;PASSWORD=haosql;USER ID=postgres"; + public static string ConnectionString2 = "PORT=5433;DATABASE=SqlSugar4xTest2;HOST=localhost;PASSWORD=haosql;USER ID=postgres"; /// /// Account have permission to create database /// 用有建库权限的数据库账号 /// - public static string ConnectionString3 = "PORT=5432;DATABASE=SqlSugar4xTest3;HOST=localhost;PASSWORD=haosql;USER ID=postgres"; + public static string ConnectionString3 = "PORT=5433;DATABASE=SqlSugar4xTest3;HOST=localhost;PASSWORD=haosql;USER ID=postgres"; } } diff --git a/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj b/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj index b28a8d3e0..2a94e7b64 100644 --- a/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj +++ b/Src/Asp.Net/PgSqlTest/PgSqlTest.csproj @@ -61,8 +61,10 @@ + + diff --git a/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs b/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs index 3776de327..63500990b 100644 --- a/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs +++ b/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs @@ -281,11 +281,19 @@ namespace SqlSugar if (readerValues != null && readerValues.Count == 1 && readerValues.First().Key == name && - readerValues.First().Value!=null&& - readerValues.First().Value.GetType()==UtilConstants.StringType&& + readerValues.First().Value != null && + readerValues.First().Value.GetType() == UtilConstants.StringType && Regex.IsMatch(readerValues.First().Value.ObjToString(), @"^\{.+\}$")) { - result.Add(name, DeserializeObject>(readerValues.First().Value.ObjToString())); + result.Add(name, DeserializeObject>(readerValues.First().Value.ObjToString())); + } + else if (item.PropertyType.FullName.IsCollectionsList()&& + readerValues.ContainsKey(item.Name.ToLower())&& + readerValues[item.Name.ToLower()]!=null&& + readerValues[item.Name.ToLower()].GetType()==UtilConstants.StringType&& + Regex.IsMatch(readerValues[item.Name.ToLower()].ToString(), @"^\[{.+\}]$")) + { + result.Add(name, DeserializeObject>>(readerValues[item.Name.ToLower()].ToString())); } else {