diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs index a97d5c0ca..a855a2204 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs @@ -203,7 +203,7 @@ namespace SqlSugar { using (dataReader) { - if (type.Name.StartsWith("KeyValuePair")) + if (UtilMethods.IsKeyValuePairType(type)) { return GetKeyValueList(type, dataReader); } @@ -231,7 +231,7 @@ namespace SqlSugar { using (dataReader) { - if (type.Name.StartsWith("KeyValuePair")) + if (UtilMethods.IsKeyValuePairType(type)) { return await GetKeyValueListAsync(type, dataReader); } @@ -256,7 +256,7 @@ namespace SqlSugar } public virtual List DataReaderToListNoUsing(Type type, IDataReader dataReader) { - if (type.Name.StartsWith("KeyValuePair")) + if (UtilMethods.IsKeyValuePairType(type)) { return GetKeyValueList(type, dataReader); } @@ -275,7 +275,7 @@ namespace SqlSugar } public virtual Task> DataReaderToListNoUsingAsync(Type type, IDataReader dataReader) { - if (type.Name.StartsWith("KeyValuePair")) + if (UtilMethods.IsKeyValuePairType(type)) { return GetKeyValueListAsync(type, dataReader); } diff --git a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs index c5d214d04..9e0b9e952 100644 --- a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs @@ -18,6 +18,10 @@ namespace SqlSugar { public class UtilMethods { + public static bool IsKeyValuePairType(Type type) + { + return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(KeyValuePair<,>); + } public static DataTable ConvertDateTimeOffsetToDateTime(DataTable table) { if (!table.Columns.Cast().Any(it => it.DataType == typeof(DateTimeOffset)))