public static Expression GetPlainTypeToDbParametersForNonEnumCompiledFunction(Expression commandParameterExpression, ClassProperty paramProperty, ClassProperty entityProperty, DbField dbField, Type valueType, Expression valueExpression) { // Automatic if (Converter.ConversionType == ConversionType.Automatic && dbField?.Type != null) { valueType = dbField.Type.GetUnderlyingType(); valueExpression = ConvertExpressionWithAutomaticConversion(valueExpression, valueType); } // DbType var dbType = (paramProperty == null ? null : TypeMapCache.Get(paramProperty.GetDeclaringType(), paramProperty.PropertyInfo)) ?? (entityProperty == null ? null : TypeMapCache.Get(entityProperty.GetDeclaringType(), entityProperty.PropertyInfo)); valueType ??= dbField?.Type.GetUnderlyingType(); if (dbType == null && valueType != null) { var resolver = new ClientTypeToDbTypeResolver(); dbType = valueType.GetDbType() ?? // type level, use TypeMapCache resolver.Resolve(valueType) ?? // type level, primitive mapping (dbField?.Type != null ? resolver.Resolve(dbField?.Type) : null); // Fallback to the database type } var dbTypeExpression = dbType == null?GetNullableTypeExpression(StaticType.DbType) : ConvertExpressionToNullableExpression(Expression.Constant(dbType), StaticType.DbType); // DbCommandExtension.CreateParameter var methodInfo = GetDbCommandCreateParameterMethod(); return(Expression.Call(methodInfo, new Expression[] { commandParameterExpression, Expression.Constant(paramProperty.GetMappedName()), ConvertExpressionToTypeExpression(valueExpression, StaticType.Object), dbTypeExpression })); }
/// <summary> /// /// </summary> /// <param name="commandParameterExpression"></param> /// <param name="paramProperty"></param> /// <param name="dbField"></param> /// <param name="valueType"></param> /// <param name="valueExpression"></param> /// <returns></returns> public static Expression GetPlainTypeToDbParametersForEnumCompiledFunction(Expression commandParameterExpression, ClassProperty paramProperty, DbField dbField, Type valueType, Expression valueExpression) { // DbType var dbType = IsPostgreSqlUserDefined(dbField) ? default : paramProperty.GetDbType() ?? valueType.GetDbType() ?? (dbField != null ? new ClientTypeToDbTypeResolver().Resolve(dbField.Type) : null) ?? (DbType?)Converter.EnumDefaultDatabaseType; // DbCommandExtension.CreateParameter var methodInfo = GetDbCommandCreateParameterMethod(); return(Expression.Call(methodInfo, new Expression[] { commandParameterExpression, Expression.Constant(paramProperty.GetMappedName()), ConvertExpressionToTypeExpression(valueExpression, StaticType.Object), ConvertExpressionToNullableExpression(Expression.Constant(dbType), StaticType.DbType) })); }