I want to map method to custom SQL, which is
CONVERT(datetime,
SWITCHOFFSET(GETUTCDATE(), DATEPART(TZOFFSET, GETUTCDATE() AT TIME ZONE 'Greenwich Standard Time')))
So I added HasDbFunction in my DbContext:
modelBuilder.HasDbFunction(typeof(DbContext).GetMethod(nameof(DbContext.GetDateTime)))
.HasTranslation(e =>
{
var GETUTCDATE = new SqlFunctionExpression("GETUTCDATE", typeof(DateTime));
var TZOFFSET = new SqlFragmentExpression("TZOFFSET");
var ATTIMEZONE = new SqlFragmentExpression(" AT TIME ZONE ");
var GreenwichStandardTime = new Expression("Greenwich Standard Time"); // expression with constant?
var EXPRESSION = new Expression(GETUTCDATE, ATTIMEZONE, GreenwichStandardTime); // expression with combine multiple exprssions?
var DATEPART = new SqlFunctionExpression("DATEPART", typeof(int), new[] { TZOFFSET , EXPRESSION }); // cannot create
var SWITCHOFFSET = new SqlFunctionExpression("SWITCHOFFSET", typeof(DateTimeOffset), new[] { GETUTCDATE, DATEPART });
var DATETIME = new SqlFragmentExpression("DATETIME");
new SqlFunctionExpression("CONVERT", typeof(DateTime), new[] { DATETIME, SWITCHOFFSET });
});
My question is how can I create GreenwichStandardTime and EXPRESSION?