Skip to content

Commit

Permalink
Follow the #690 review suggestion to make adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
fredliex committed Jan 4, 2021
1 parent aea430a commit 0f340dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
25 changes: 11 additions & 14 deletions RepoDb.Core/RepoDb/Extensions/DbCommandExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,22 +257,19 @@ private static void CreateParametersInternal(IDbCommand command,
returnType = underlyingType;
}

// DbType
/*
* DbType, Decide in the following logical order
* 1. PropertyHandler.Set method's ReturnType, use Primitive mapping.
* 2. Property Type, use TypeMapCache.
* 3. Property value's Type, use TypeMapCache.
* 4. Property Type, use Primitive mapping.
* 5. Specialized enum, use Converter.EnumDefaultDatabaseType.
*/
var dbType = (returnType != null ? clientTypeToDbTypeResolver.Resolve(returnType) : null) ??
classProperty.GetDbType() ??
value?.GetType()?.GetDbType();

// Try get fallback dbType by classProperty to avoid being mistaken as string when value is null.
if (dbType == null && classProperty != null)
{
dbType = clientTypeToDbTypeResolver.Resolve(classProperty.PropertyInfo.PropertyType);
}

// Specialized enum
if (dbType == null && isEnum.HasValue && isEnum.Value == true)
{
dbType = Converter.EnumDefaultDatabaseType;
}
value?.GetType()?.GetDbType() ??
(classProperty != null ? clientTypeToDbTypeResolver.Resolve(classProperty.PropertyInfo.PropertyType) : null) ??
(isEnum == true ? Converter.EnumDefaultDatabaseType : (DbType?)null);

// Add the parameter
command.Parameters.Add(command.CreateParameter(name, value, dbType));
Expand Down
3 changes: 2 additions & 1 deletion RepoDb.Core/RepoDb/Reflection/Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,8 @@ internal static Expression GetDictionaryStringObjectDbParameterValueAssignmentEx
return Expression.Call(parameterVariableExpression, GetDbParameterValueSetMethod(), expression);
}

private static DbType? GetDbType(ClassProperty classProperty, Type dbFieldType)
private static DbType? GetDbType(ClassProperty classProperty,
Type dbFieldType)
{
var dbType = classProperty?.GetDbType();
if (dbType == null)
Expand Down

0 comments on commit 0f340dd

Please sign in to comment.