diff --git a/Src/Asp.Net/MySqlTest/MySqlTest.csproj b/Src/Asp.Net/MySqlTest/MySqlTest.csproj index 647453aa8..94a3890c7 100644 --- a/Src/Asp.Net/MySqlTest/MySqlTest.csproj +++ b/Src/Asp.Net/MySqlTest/MySqlTest.csproj @@ -86,6 +86,7 @@ + diff --git a/Src/Asp.Net/MySqlTest/UnitTest/Main.cs b/Src/Asp.Net/MySqlTest/UnitTest/Main.cs index e92d0cf26..a249b177d 100644 --- a/Src/Asp.Net/MySqlTest/UnitTest/Main.cs +++ b/Src/Asp.Net/MySqlTest/UnitTest/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + UnitCustom01.Init(); Insert(); Queue(); CodeFirst(); diff --git a/Src/Asp.Net/MySqlTest/UnitTest/UnitCustom01.cs b/Src/Asp.Net/MySqlTest/UnitTest/UnitCustom01.cs new file mode 100644 index 000000000..eeefa398d --- /dev/null +++ b/Src/Asp.Net/MySqlTest/UnitTest/UnitCustom01.cs @@ -0,0 +1,117 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + public class UnitCustom01 + { + public static void Init() + { + var ssc = new SqlSugarClient(new ConnectionConfig() + + { + + ConnectionString = OrmTest.Config.ConnectionString, + + DbType = SqlSugar.DbType.MySql, //必填 + + IsAutoCloseConnection = true + + }); + ssc.CodeFirst.InitTables(); + var expMethods = new List(); + + expMethods.Add(new SqlFuncExternal() + + { + + UniqueMethodName = "SumSugar", + + MethodValue = (expInfo, dbType, expContext) => + + { + + if (dbType == DbType.SqlServer) + + return string.Format("SUM({0})", expInfo.Args[0].MemberName); + + else if (dbType == DbType.MySql) + + return string.Format("SUM({0})", expInfo.Args[0].MemberName); + + else + + throw new Exception("未实现"); + + } + + }); + + ssc.CurrentConnectionConfig.ConfigureExternalServices = new ConfigureExternalServices() + + { + + SqlFuncServices = expMethods //set ext method + + }; + + try + + { + ssc.Insertable(new Student() { Age = 1, Createtime = DateTime.Now, Grade = 1, Id = 1, Name = "a", Schoolid = 1 }).ExecuteCommand(); + ssc.Insertable(new Student() { Age = 1, Createtime = DateTime.Now, Grade = 1, Id = 1, Name = "a", Schoolid = 1 }).ExecuteCommand(); + var sss12 = ssc.Queryable().GroupBy(o => o.Name).Select(o => new { Age = SqlFunc.AggregateSum(o.Age) }).ToList(); + + } + + catch (Exception e) + + { + + + + } + } + } + + [SugarTable("unitstudent1111")] + public class Student + { + /// + /// + /// + [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "schoolid")] + public int? Schoolid { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "name")] + public string Name { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "createtime")] + public DateTime? Createtime { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "age")] + public int? Age { get; set; } + /// + /// + /// + [SugarColumn(ColumnName = "grade")] + public int? Grade { get; set; } + } + + +} diff --git a/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs b/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs index 219cbe93b..9d7eb770c 100644 --- a/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs +++ b/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs @@ -336,7 +336,7 @@ namespace SqlSugar addValue = null; } } - else if (item.PropertyType == UtilConstants.IntType) + else if (UtilMethods.GetUnderType(item.PropertyType) == UtilConstants.IntType) { addValue = Convert.ToInt32(addValue); }