Skip to content

Commit

Permalink
Resolved issues after upgrade to EFCore v9.
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenRasmussen committed Sep 27, 2024
1 parent abeff46 commit 815db4c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public abstract class BaseNodaTimeMemberTranslator : IMemberTranslator
private readonly ISqlExpressionFactory _sqlExpressionFactory;
private readonly Dictionary<string, string> _datePartMapping;
private readonly Type _declaringType;
private static List<bool> _argumentsPropagateNullability = new List<bool>
{
false,
false,
};

public BaseNodaTimeMemberTranslator([NotNull] ISqlExpressionFactory sqlExpressionFactory, [NotNull] Type declaringType, [NotNull] Dictionary<string, string> datePartMapping)
{
Expand All @@ -35,7 +40,7 @@ public SqlExpression Translate(SqlExpression instance, MemberInfo member, Type r
"DATEPART",
new[] { _sqlExpressionFactory.Fragment(datePart), instance },
false,
null,
_argumentsPropagateNullability,
returnType);
}
else if (member.Name == nameof(LocalDateTime.Date) && returnType == typeof(LocalDate))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ public abstract class BaseNodaTimeMethodCallTranslator : IMethodCallTranslator
private readonly Dictionary<MethodInfo, string> _methodInfoDateDiffMapping;
private readonly Dictionary<MethodInfo, string> _methodInfoDateDiffBigMapping;

private static List<bool> _2argumentsPropagateNullability = new List<bool>
{
false,
false,
};

private static List<bool> _3argumentsPropagateNullability = new List<bool>
{
false,
false,
false,
};

public BaseNodaTimeMethodCallTranslator(
ISqlExpressionFactory sqlExpressionFactory,
Dictionary<MethodInfo, string> methodInfoDateAddMapping,
Expand All @@ -41,17 +54,17 @@ public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadO
|| (sqlConstant.Value is long && ((long)sqlConstant.Value >= int.MaxValue || (long)sqlConstant.Value <= int.MinValue)))
? null
: _sqlExpressionFactory.Function(
"DATEADD",
new[]
name: "DATEADD",
arguments: new[]
{
_sqlExpressionFactory.Fragment(dateAddPart),
_sqlExpressionFactory.Convert(arguments[0], typeof(int)),
instance
},
false,
null,
instance.Type,
instance.TypeMapping);
nullable: false,
argumentsPropagateNullability: _3argumentsPropagateNullability,
returnType: instance.Type,
typeMapping: instance.TypeMapping);
}
else if (_methodInfoDateAddExtensionMapping != null && _methodInfoDateAddExtensionMapping.TryGetValue(method, out var dateAddExtensionPart))
{
Expand All @@ -60,31 +73,31 @@ public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadO
|| (sqlConstant.Value is long && ((long)sqlConstant.Value >= int.MaxValue || (long)sqlConstant.Value <= int.MinValue)))
? null
: _sqlExpressionFactory.Function(
"DATEADD",
new[]
name: "DATEADD",
arguments: new[]
{
_sqlExpressionFactory.Fragment(dateAddExtensionPart),
_sqlExpressionFactory.Convert(arguments[1], typeof(int)),
arguments[0]
},
false,
null,
arguments[0].Type,
arguments[0].TypeMapping);
nullable: false,
argumentsPropagateNullability: _3argumentsPropagateNullability,
returnType: arguments[0].Type,
typeMapping: arguments[0].TypeMapping);
}
else if (_methodInfoDatePartExtensionMapping != null && _methodInfoDatePartExtensionMapping.TryGetValue(method, out var datePart))
{
return _sqlExpressionFactory.Function(
"DATEPART",
new[]
name: "DATEPART",
arguments: new[]
{
_sqlExpressionFactory.Fragment(datePart),
arguments[0]
},
false,
null,
method.ReturnType,
null);
nullable: false,
argumentsPropagateNullability: _2argumentsPropagateNullability,
returnType: method.ReturnType,
typeMapping: null);
}
else if (_methodInfoDateDiffMapping != null && _methodInfoDateDiffMapping.TryGetValue(method, out var dateDiffDatePart))
{
Expand All @@ -96,12 +109,12 @@ public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadO
endDate = _sqlExpressionFactory.ApplyTypeMapping(endDate, typeMapping);

return _sqlExpressionFactory.Function(
"DATEDIFF",
new[] { _sqlExpressionFactory.Fragment(dateDiffDatePart), startDate, endDate },
false,
null,
method.ReturnType,
null);
name: "DATEDIFF",
arguments: new[] { _sqlExpressionFactory.Fragment(dateDiffDatePart), startDate, endDate },
nullable: false,
argumentsPropagateNullability: _3argumentsPropagateNullability,
returnType: method.ReturnType,
typeMapping: null);
}
else if (_methodInfoDateDiffBigMapping != null && _methodInfoDateDiffBigMapping.TryGetValue(method, out var dateDiffBigDatePart))
{
Expand All @@ -113,12 +126,12 @@ public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadO
endDate = _sqlExpressionFactory.ApplyTypeMapping(endDate, typeMapping);

return _sqlExpressionFactory.Function(
"DATEDIFF_BIG",
new[] { _sqlExpressionFactory.Fragment(dateDiffBigDatePart), startDate, endDate },
false,
null,
method.ReturnType,
null);
name: "DATEDIFF_BIG",
arguments: new[] { _sqlExpressionFactory.Fragment(dateDiffBigDatePart), startDate, endDate },
nullable: false,
argumentsPropagateNullability: _3argumentsPropagateNullability,
returnType: method.ReturnType,
typeMapping: null);
}
return null;
}
Expand Down

0 comments on commit 815db4c

Please sign in to comment.