diff --git a/Src/Asp.Net/MySqlTest/Program.cs b/Src/Asp.Net/MySqlTest/Program.cs index a7ddb3bbc..6d5401148 100644 --- a/Src/Asp.Net/MySqlTest/Program.cs +++ b/Src/Asp.Net/MySqlTest/Program.cs @@ -17,32 +17,32 @@ namespace OrmTest { static void Main(string[] args) { - // /***Unit Test***/ - new Field(1).Init(); - new Where(1).Init(); - new Method(1).Init(); - new JoinQuery(1).Init(); - new SingleQuery(1).Init(); - new SelectQuery(1).Init(); - new AutoClose(1).Init(); - new Insert(1).Init(); - new Delete(1).Init(); - new Update(1).Init(); - new Mapping(1).Init(); - // new DataTest(1).Init(); + //// /***Unit Test***/ + new Field(1).Init(); + new Where(1).Init(); + new Method(1).Init(); + new JoinQuery(1).Init(); + new SingleQuery(1).Init(); + new SelectQuery(1).Init(); + new AutoClose(1).Init(); + new Insert(1).Init(); + new Delete(1).Init(); + new Update(1).Init(); + new Mapping(1).Init(); + new DataTest(1).Init(); - // /***Performance Test***/ - // new SqlSugarPerformance(100).Select(); + // /***Performance Test***/ + // new SqlSugarPerformance(100).Select(); /***Demo***/ OrmTest.Demo.Query.Init(); - //OrmTest.Demo.Insert.Init(); - //OrmTest.Demo.Delete.Init(); - //OrmTest.Demo.Update.Init(); - // OrmTest.Demo.DbFirst.Init(); - //OrmTest.Demo.JoinSql.Init(); - //OrmTest.Demo.Filter.Init(); - //OrmTest.Demo.ComplexModel.Init(); + OrmTest.Demo.Insert.Init(); + OrmTest.Demo.Delete.Init(); + OrmTest.Demo.Update.Init(); + OrmTest.Demo.DbFirst.Init(); + OrmTest.Demo.JoinSql.Init(); + OrmTest.Demo.Filter.Init(); + OrmTest.Demo.ComplexModel.Init(); OrmTest.Demo.CodeFirst.Init(); } } diff --git a/Src/Asp.Net/MySqlTest/UnitTest/DataTest.cs b/Src/Asp.Net/MySqlTest/UnitTest/DataTest.cs index c0d28941e..df92da1a0 100644 --- a/Src/Asp.Net/MySqlTest/UnitTest/DataTest.cs +++ b/Src/Asp.Net/MySqlTest/UnitTest/DataTest.cs @@ -17,6 +17,7 @@ namespace OrmTest.UnitTest public void Init() { + var guid = Guid.Parse("d8268a7e-a2d1-4329-9990-9bd801292415"); var db = GetInstance(); db.DbMaintenance.TruncateTable("DataTestInfo"); var insertObject = new DataTestInfo() @@ -27,8 +28,8 @@ namespace OrmTest.UnitTest Decimal2 = 2, Float1 = 3, Float2 = 4, - Guid1 = Guid.Empty, - Guid2 = null, + Guid1 = guid, + Guid2 = guid, Image1 = new byte[] { 1, 2 }, Image2 = new byte[] { 2, 3 }, Int2 = 6, @@ -41,12 +42,13 @@ namespace OrmTest.UnitTest var id = db.Insertable(insertObject).ExecuteReutrnIdentity(); var data = db.Queryable().InSingle(id); if ( - insertObject.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") != data.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") || + insertObject.Datetime1.ToString("yyyy-MM-dd") != data.Datetime1.ToString("yyyy-MM-dd") || insertObject.Decimal1 != data.Decimal1 || insertObject.Float1 != data.Float1 || insertObject.Float2 != data.Float2 || insertObject.Int2 != data.Int2 || insertObject.Money1 != data.Money1 || + insertObject.Guid2!=data.Guid2|| string.Join(",", insertObject.Varbinary1) != string.Join(",", data.Varbinary1) || insertObject.String != data.String) { @@ -56,7 +58,7 @@ namespace OrmTest.UnitTest db.Updateable(data).ExecuteCommand(); data = db.Queryable().InSingle(id); if ( - insertObject.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") != data.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") || + insertObject.Datetime1.ToString("yyyy-MM-dd") != data.Datetime1.ToString("yyyy-MM-dd") || insertObject.Decimal1 != data.Decimal1 || (insertObject.Float1+1) != data.Float1 || insertObject.Float2 != data.Float2 || @@ -70,7 +72,7 @@ namespace OrmTest.UnitTest } public SqlSugarClient GetInstance() { - SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true }); + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.MySql, IsAutoCloseConnection = true }); return db; } } diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs index 229ac4b7b..01e48a170 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs @@ -15,7 +15,7 @@ namespace SqlSugar #endregion #region Public methods - public string GetDbTypeName(string csharpTypeName) + public virtual string GetDbTypeName(string csharpTypeName) { if (csharpTypeName == PubConst.ByteArrayType.Name) { diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs index 110446153..b7660826b 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs @@ -36,6 +36,8 @@ namespace SqlSugar private static readonly MethodInfo getInt32 = typeof(IDataRecord).GetMethod("GetInt32", new Type[] { typeof(int) }); private static readonly MethodInfo getInt64 = typeof(IDataRecord).GetMethod("GetInt64", new Type[] { typeof(int) }); private static readonly MethodInfo getString = typeof(IDataRecord).GetMethod("GetString", new Type[] { typeof(int) }); + private static readonly MethodInfo getStringGuid = typeof(IDataRecordExtensions).GetMethod("GetStringGuid"); + private static readonly MethodInfo getConvertStringGuid = typeof(IDataRecordExtensions).GetMethod("GetConvertStringGuid"); private static readonly MethodInfo getEnum = typeof(IDataRecordExtensions).GetMethod("GetEnum"); private static readonly MethodInfo getConvertString = typeof(IDataRecordExtensions).GetMethod("GetConvertString"); private static readonly MethodInfo getConvertFloat = typeof(IDataRecordExtensions).GetMethod("GetConvertFloat"); @@ -178,6 +180,9 @@ namespace SqlSugar case CSharpDataType.@string: CheckType(bind.StringThrow, bindProperyTypeName, validPropertyName, propertyName); method = getString; + if (bindProperyTypeName == "guid") { + method = getConvertStringGuid ; + } break; case CSharpDataType.DateTime: CheckType(bind.DateThrow, bindProperyTypeName, validPropertyName, propertyName); @@ -198,7 +203,7 @@ namespace SqlSugar case CSharpDataType.Guid: CheckType(bind.GuidThrow, bindProperyTypeName, validPropertyName, propertyName); if (bindProperyTypeName == "guid") - method = isNullableType ? getConvertGuid : getGuid; + method = isNullableType ? getConvertStringGuid : getStringGuid; break; case CSharpDataType.@byte: method = isNullableType ? getConvertByte : getByte; diff --git a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs index 3eddf4895..a6e58033d 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataRecordExtensions.cs @@ -7,6 +7,23 @@ namespace SqlSugar { public static partial class IDataRecordExtensions { + + public static Guid GetStringGuid(this IDataRecord dr, int i) + { + var reval =Guid.Parse(dr.GetValue(i).ToString()); + return reval; + } + + public static Guid? GetConvertStringGuid(this IDataRecord dr, int i) + { + if (dr.IsDBNull(i)) + { + return Guid.Empty; + } + var reval = Guid.Parse(dr.GetValue(i).ToString()); + return reval; + } + public static bool? GetConvertBoolean(this IDataRecord dr, int i) { if (dr.IsDBNull(i)) @@ -57,7 +74,7 @@ namespace SqlSugar return reval; } - + public static double? GetConvertDouble(this IDataRecord dr, int i) { if (dr.IsDBNull(i)) @@ -124,7 +141,7 @@ namespace SqlSugar { return null; } - var reval =Convert.ToString(dr.GetValue(i)); + var reval = Convert.ToString(dr.GetValue(i)); return reval; } @@ -138,7 +155,7 @@ namespace SqlSugar } - public static T GetOther(this IDataReader dr, int i) + public static T GetOther(this IDataReader dr, int i) { return (T)Convert.ChangeType(dr.GetValue(i), typeof(T)); } @@ -161,7 +178,7 @@ namespace SqlSugar return t; } - public static object GetEntity(this IDataReader dr, SqlSugarClient context) + public static object GetEntity(this IDataReader dr, SqlSugarClient context) { return null; } diff --git a/Src/Asp.Net/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs b/Src/Asp.Net/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs index caa5c5fc6..2fe00688e 100644 --- a/Src/Asp.Net/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs +++ b/Src/Asp.Net/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs @@ -1,10 +1,28 @@ using System; using System.Collections.Generic; +using System.Linq; namespace SqlSugar { public class MySqlDbBind : DbBindProvider { + public override string GetDbTypeName(string csharpTypeName) + { + if (csharpTypeName == PubConst.ByteArrayType.Name) + { + return "blob"; + } + if (csharpTypeName == "Int32") + csharpTypeName = "int"; + if (csharpTypeName == "Int16") + csharpTypeName = "short"; + if (csharpTypeName == "Int64") + csharpTypeName = "long"; + if (csharpTypeName == "Boolean") + csharpTypeName = "bool"; + var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase)); + return mappings.IsValuable() ? mappings.First().Key : "varchar"; + } public override List> MappingTypes { get @@ -50,5 +68,12 @@ namespace SqlSugar }; } } + public override List StringThrow + { + get + { + return new List() { "int32", "datetime", "decimal", "double", "byte"}; + } + } } }