Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Efcore.Pg
提交
227a4bcc
E
Efcore.Pg
项目概览
jobily
/
Efcore.Pg
12 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
Efcore.Pg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
227a4bcc
编写于
6月 21, 2022
作者:
S
Shay Rojansky
提交者:
GitHub
6月 21, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Switch to using the new EF Core AtTimeZoneExpression (#2409)
Instead of our PG-specific one.
上级
6a1d7a81
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
33 addition
and
45 deletion
+33
-45
src/EFCore.PG/Query/Expressions/Internal/PostgresBinaryExpression.cs
...PG/Query/Expressions/Internal/PostgresBinaryExpression.cs
+0
-2
src/EFCore.PG/Query/Expressions/PostgresExpressionType.cs
src/EFCore.PG/Query/Expressions/PostgresExpressionType.cs
+0
-2
src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs
src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs
+0
-2
src/EFCore.PG/Query/NpgsqlSqlExpressionFactory.cs
src/EFCore.PG/Query/NpgsqlSqlExpressionFactory.cs
+18
-24
test/EFCore.PG.FunctionalTests/Query/LegacyTimestampQueryTest.cs
...Core.PG.FunctionalTests/Query/LegacyTimestampQueryTest.cs
+1
-1
test/EFCore.PG.FunctionalTests/Query/TimestampQueryTest.cs
test/EFCore.PG.FunctionalTests/Query/TimestampQueryTest.cs
+9
-9
test/EFCore.PG.NodaTime.FunctionalTests/NodaTimeQueryNpgsqlTest.cs
...re.PG.NodaTime.FunctionalTests/NodaTimeQueryNpgsqlTest.cs
+5
-5
未找到文件。
src/EFCore.PG/Query/Expressions/Internal/PostgresBinaryExpression.cs
浏览文件 @
227a4bcc
...
...
@@ -99,8 +99,6 @@ protected override void Print(ExpressionPrinter expressionPrinter)
PostgresExpressionType
.
ContainedBy
=>
"<@"
,
PostgresExpressionType
.
Overlaps
=>
"&&"
,
PostgresExpressionType
.
AtTimeZone
=>
"AT TIME ZONE"
,
PostgresExpressionType
.
NetworkContainedByOrEqual
=>
"<<="
,
PostgresExpressionType
.
NetworkContainsOrEqual
=>
">>="
,
PostgresExpressionType
.
NetworkContainsOrContainedBy
=>
"&&"
,
...
...
src/EFCore.PG/Query/Expressions/PostgresExpressionType.cs
浏览文件 @
227a4bcc
...
...
@@ -9,8 +9,6 @@ public enum PostgresExpressionType
ContainedBy
,
// << (inet/cidr), <@
Overlaps
,
// &&
AtTimeZone
,
// AT TIME ZONE
NetworkContainedByOrEqual
,
// <<=
NetworkContainsOrEqual
,
// >>=
NetworkContainsOrContainedBy
,
// &&
...
...
src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs
浏览文件 @
227a4bcc
...
...
@@ -270,8 +270,6 @@ protected virtual Expression VisitPostgresBinary(PostgresBinaryExpression binary
PostgresExpressionType
.
ContainedBy
=>
"<@"
,
PostgresExpressionType
.
Overlaps
=>
"&&"
,
PostgresExpressionType
.
AtTimeZone
=>
"AT TIME ZONE"
,
PostgresExpressionType
.
NetworkContainedByOrEqual
=>
"<<="
,
PostgresExpressionType
.
NetworkContainsOrEqual
=>
">>="
,
PostgresExpressionType
.
NetworkContainsOrContainedBy
=>
"&&"
,
...
...
src/EFCore.PG/Query/NpgsqlSqlExpressionFactory.cs
浏览文件 @
227a4bcc
...
...
@@ -61,44 +61,38 @@ public NpgsqlSqlExpressionFactory(SqlExpressionFactoryDependencies dependencies)
typeMapping
);
}
public
virtual
PostgresBinary
Expression
AtUtc
(
public
virtual
AtTimeZone
Expression
AtUtc
(
SqlExpression
timestamp
,
RelationalTypeMapping
?
typeMapping
=
null
)
=>
AtTimeZone
(
timestamp
,
Constant
(
"UTC"
),
timestamp
.
Type
);
public
virtual
PostgresBinary
Expression
AtTimeZone
(
public
virtual
AtTimeZone
Expression
AtTimeZone
(
SqlExpression
timestamp
,
SqlExpression
timeZone
,
Type
type
,
RelationalTypeMapping
?
typeMapping
=
null
)
{
// PostgreSQL AT TIME ZONE flips the given type from timestamptz to timestamp and vice versa
// See https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-ZONECONVERT
typeMapping
??=
FlipTimestampTypeMapping
(
timestamp
.
TypeMapping
??
_typeMappingSource
.
FindMapping
(
timestamp
.
Type
,
Dependencies
.
Model
)!);
if
(
typeMapping
is
null
)
{
// PostgreSQL AT TIME ZONE flips the given type from timestamptz to timestamp and vice versa
// See https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-ZONECONVERT
typeMapping
=
timestamp
.
TypeMapping
??
_typeMappingSource
.
FindMapping
(
timestamp
.
Type
,
Dependencies
.
Model
)!;
var
storeType
=
typeMapping
.
StoreType
;
typeMapping
=
storeType
.
StartsWith
(
"timestamp with time zone"
,
StringComparison
.
Ordinal
)
||
storeType
.
StartsWith
(
"timestamptz"
,
StringComparison
.
Ordinal
)
?
_typeMappingSource
.
FindMapping
(
"timestamp without time zone"
)!
:
storeType
.
StartsWith
(
"timestamp without time zone"
,
StringComparison
.
Ordinal
)
||
storeType
.
StartsWith
(
"timestamp"
,
StringComparison
.
Ordinal
)
?
_typeMappingSource
.
FindMapping
(
"timestamp with time zone"
)!
:
throw
new
ArgumentException
(
$"timestamp argument to AtTimeZone had unknown store type
{
storeType
}
"
,
nameof
(
timestamp
));
}
return
new
PostgresBinaryExpression
(
PostgresExpressionType
.
AtTimeZone
,
return
new
AtTimeZoneExpression
(
ApplyDefaultTypeMapping
(
timestamp
),
ApplyDefaultTypeMapping
(
timeZone
),
type
,
typeMapping
);
RelationalTypeMapping
FlipTimestampTypeMapping
(
RelationalTypeMapping
mapping
)
{
var
storeType
=
mapping
.
StoreType
;
if
(
storeType
.
StartsWith
(
"timestamp with time zone"
,
StringComparison
.
Ordinal
)
||
storeType
.
StartsWith
(
"timestamptz"
,
StringComparison
.
Ordinal
))
{
return
_typeMappingSource
.
FindMapping
(
"timestamp without time zone"
)!;
}
if
(
storeType
.
StartsWith
(
"timestamp without time zone"
,
StringComparison
.
Ordinal
)
||
storeType
.
StartsWith
(
"timestamp"
,
StringComparison
.
Ordinal
))
{
return
_typeMappingSource
.
FindMapping
(
"timestamp with time zone"
)!;
}
throw
new
ArgumentException
(
$"timestamp argument to AtTimeZone had unknown store type
{
storeType
}
"
,
nameof
(
timestamp
));
}
}
public
virtual
PostgresILikeExpression
ILike
(
...
...
test/EFCore.PG.FunctionalTests/Query/LegacyTimestampQueryTest.cs
浏览文件 @
227a4bcc
...
...
@@ -64,7 +64,7 @@ public virtual async Task Where_datetime_utcnow()
SELECT e.""Id"", e.""TimestampDateTime"", e.""TimestampDateTimeOffset"", e.""TimestamptzDateTime""
FROM ""Entities"" AS e
WHERE
now() AT TIME ZONE 'UTC'
<> @__myDatetime_0"
);
WHERE
(now() AT TIME ZONE 'UTC')
<> @__myDatetime_0"
);
}
#
region
Support
...
...
test/EFCore.PG.FunctionalTests/Query/TimestampQueryTest.cs
浏览文件 @
227a4bcc
...
...
@@ -387,7 +387,7 @@ public async Task DateTimeOffset_DateTime(bool async)
AssertSql
(
@"SELECT e.""Id"", e.""TimestampDateTime"", e.""TimestampDateTimeArray"", e.""TimestampDateTimeOffset"", e.""TimestampDateTimeOffsetArray"", e.""TimestampDateTimeRange"", e.""TimestamptzDateTime"", e.""TimestamptzDateTimeArray"", e.""TimestamptzDateTimeRange""
FROM ""Entities"" AS e
WHERE
e.""TimestampDateTimeOffset"" AT TIME ZONE 'UTC'
= TIMESTAMP '1998-04-12 13:26:38'"
);
WHERE
(e.""TimestampDateTimeOffset"" AT TIME ZONE 'UTC')
= TIMESTAMP '1998-04-12 13:26:38'"
);
}
[
ConditionalTheory
]
...
...
@@ -534,7 +534,7 @@ public async Task DateTime_SpecifyKind_on_timestamp_to_utc(bool async)
AssertSql
(
@"SELECT e.""Id"", e.""TimestampDateTime"", e.""TimestampDateTimeArray"", e.""TimestampDateTimeOffset"", e.""TimestampDateTimeOffsetArray"", e.""TimestampDateTimeRange"", e.""TimestamptzDateTime"", e.""TimestamptzDateTimeArray"", e.""TimestamptzDateTimeRange""
FROM ""Entities"" AS e
WHERE
e.""TimestampDateTime"" AT TIME ZONE 'UTC'
= TIMESTAMPTZ '1998-04-12 15:26:38Z'"
);
WHERE
(e.""TimestampDateTime"" AT TIME ZONE 'UTC')
= TIMESTAMPTZ '1998-04-12 15:26:38Z'"
);
}
[
ConditionalTheory
]
...
...
@@ -549,7 +549,7 @@ public async Task DateTime_SpecifyKind_on_timestamptz_to_unspecified(bool async)
AssertSql
(
@"SELECT e.""Id"", e.""TimestampDateTime"", e.""TimestampDateTimeArray"", e.""TimestampDateTimeOffset"", e.""TimestampDateTimeOffsetArray"", e.""TimestampDateTimeRange"", e.""TimestamptzDateTime"", e.""TimestamptzDateTimeArray"", e.""TimestamptzDateTimeRange""
FROM ""Entities"" AS e
WHERE
e.""TimestamptzDateTime"" AT TIME ZONE 'UTC'
= TIMESTAMP '1998-04-12 13:26:38'"
);
WHERE
(e.""TimestamptzDateTime"" AT TIME ZONE 'UTC')
= TIMESTAMP '1998-04-12 13:26:38'"
);
}
[
ConditionalTheory
]
...
...
@@ -564,7 +564,7 @@ public async Task DateTime_SpecifyKind_on_timestamptz_to_local(bool async)
AssertSql
(
@"SELECT e.""Id"", e.""TimestampDateTime"", e.""TimestampDateTimeArray"", e.""TimestampDateTimeOffset"", e.""TimestampDateTimeOffsetArray"", e.""TimestampDateTimeRange"", e.""TimestamptzDateTime"", e.""TimestamptzDateTimeArray"", e.""TimestamptzDateTimeRange""
FROM ""Entities"" AS e
WHERE
e.""TimestamptzDateTime"" AT TIME ZONE 'UTC'
= TIMESTAMP '1998-04-12 13:26:38'"
);
WHERE
(e.""TimestamptzDateTime"" AT TIME ZONE 'UTC')
= TIMESTAMP '1998-04-12 13:26:38'"
);
}
[
ConditionalFact
]
...
...
@@ -598,7 +598,7 @@ public virtual async Task Where_ConvertTimeBySystemTimeZoneId_on_DateTime_timest
AssertSql
(
@"SELECT e.""Id"", e.""TimestampDateTime"", e.""TimestampDateTimeArray"", e.""TimestampDateTimeOffset"", e.""TimestampDateTimeOffsetArray"", e.""TimestampDateTimeRange"", e.""TimestamptzDateTime"", e.""TimestamptzDateTimeArray"", e.""TimestamptzDateTimeRange""
FROM ""Entities"" AS e
WHERE
e.""TimestamptzDateTime"" AT TIME ZONE 'Europe/Berlin'
= TIMESTAMP '1998-04-12 15:26:38'"
);
WHERE
(e.""TimestamptzDateTime"" AT TIME ZONE 'Europe/Berlin')
= TIMESTAMP '1998-04-12 15:26:38'"
);
}
[
ConditionalFact
]
...
...
@@ -660,7 +660,7 @@ public virtual async Task DateOnly_FromDateTime_with_timestamptz(bool async)
AssertSql
(
@"SELECT e.""Id"", e.""TimestampDateTime"", e.""TimestampDateTimeArray"", e.""TimestampDateTimeOffset"", e.""TimestampDateTimeOffsetArray"", e.""TimestampDateTimeRange"", e.""TimestamptzDateTime"", e.""TimestamptzDateTimeArray"", e.""TimestamptzDateTimeRange""
FROM ""Entities"" AS e
WHERE CAST(
e.""TimestamptzDateTime"" AT TIME ZONE 'UTC'
AS date) = DATE '1998-04-12'"
);
WHERE CAST(
(e.""TimestamptzDateTime"" AT TIME ZONE 'UTC')
AS date) = DATE '1998-04-12'"
);
}
[
ConditionalTheory
]
...
...
@@ -692,7 +692,7 @@ public virtual async Task DateOnly_ToDateTime_with_timestamptz(bool async)
AssertSql
(
@"SELECT e.""Id"", e.""TimestampDateTime"", e.""TimestampDateTimeArray"", e.""TimestampDateTimeOffset"", e.""TimestampDateTimeOffsetArray"", e.""TimestampDateTimeRange"", e.""TimestamptzDateTime"", e.""TimestamptzDateTimeArray"", e.""TimestamptzDateTimeRange""
FROM ""Entities"" AS e
WHERE (CAST(
e.""TimestamptzDateTime"" AT TIME ZONE 'UTC'
AS date) + TIME '15:26:38') = TIMESTAMP '1998-04-12 15:26:38'"
);
WHERE (CAST(
(e.""TimestamptzDateTime"" AT TIME ZONE 'UTC')
AS date) + TIME '15:26:38') = TIMESTAMP '1998-04-12 15:26:38'"
);
}
#
endregion
DateOnly
...
...
@@ -728,7 +728,7 @@ public virtual async Task TimeOnly_FromDateTime_with_timestamptz(bool async)
AssertSql
(
@"SELECT e.""Id"", e.""TimestampDateTime"", e.""TimestampDateTimeArray"", e.""TimestampDateTimeOffset"", e.""TimestampDateTimeOffsetArray"", e.""TimestampDateTimeRange"", e.""TimestamptzDateTime"", e.""TimestamptzDateTimeArray"", e.""TimestamptzDateTimeRange""
FROM ""Entities"" AS e
WHERE CAST(
e.""TimestamptzDateTime"" AT TIME ZONE 'UTC'
AS time without time zone) = TIME '13:26:38'"
);
WHERE CAST(
(e.""TimestamptzDateTime"" AT TIME ZONE 'UTC')
AS time without time zone) = TIME '13:26:38'"
);
}
[
ConditionalTheory
]
...
...
@@ -744,7 +744,7 @@ public virtual async Task TimeOnly_ToTimeSpan(bool async)
AssertSql
(
@"SELECT e.""Id"", e.""TimestampDateTime"", e.""TimestampDateTimeArray"", e.""TimestampDateTimeOffset"", e.""TimestampDateTimeOffsetArray"", e.""TimestampDateTimeRange"", e.""TimestamptzDateTime"", e.""TimestamptzDateTimeArray"", e.""TimestamptzDateTimeRange""
FROM ""Entities"" AS e
WHERE CAST(
e.""TimestamptzDateTime"" AT TIME ZONE 'UTC'
AS time without time zone) = TIME '13:26:38'"
);
WHERE CAST(
(e.""TimestamptzDateTime"" AT TIME ZONE 'UTC')
AS time without time zone) = TIME '13:26:38'"
);
}
#
endregion
TimeOnly
...
...
test/EFCore.PG.NodaTime.FunctionalTests/NodaTimeQueryNpgsqlTest.cs
浏览文件 @
227a4bcc
...
...
@@ -311,7 +311,7 @@ public async Task LocalDateTime_InZoneLeniently_ToInstant(bool async)
SELECT n.""Id"", n.""DateInterval"", n.""Duration"", n.""Instant"", n.""InstantRange"", n.""Interval"", n.""LocalDate"", n.""LocalDate2"", n.""LocalDateRange"", n.""LocalDateTime"", n.""LocalTime"", n.""Long"", n.""OffsetTime"", n.""Period"", n.""TimeZoneId"", n.""ZonedDateTime""
FROM ""NodaTimeTypes"" AS n
WHERE
n.""LocalDateTime"" AT TIME ZONE 'Europe/Berlin'
= @__ToInstant_0"
);
WHERE
(n.""LocalDateTime"" AT TIME ZONE 'Europe/Berlin')
= @__ToInstant_0"
);
}
[
ConditionalTheory
]
...
...
@@ -330,7 +330,7 @@ public async Task LocalDateTime_InZoneLeniently_ToInstant_with_column_time_zone(
SELECT n.""Id"", n.""DateInterval"", n.""Duration"", n.""Instant"", n.""InstantRange"", n.""Interval"", n.""LocalDate"", n.""LocalDate2"", n.""LocalDateRange"", n.""LocalDateTime"", n.""LocalTime"", n.""Long"", n.""OffsetTime"", n.""Period"", n.""TimeZoneId"", n.""ZonedDateTime""
FROM ""NodaTimeTypes"" AS n
WHERE
n.""LocalDateTime"" AT TIME ZONE n.""TimeZoneId""
= @__ToInstant_0"
);
WHERE
(n.""LocalDateTime"" AT TIME ZONE n.""TimeZoneId"")
= @__ToInstant_0"
);
}
#
endregion
LocalDateTime
...
...
@@ -1176,7 +1176,7 @@ public async Task Instance_InZone_LocalDateTime(bool async)
AssertSql
(
@"SELECT n.""Id"", n.""DateInterval"", n.""Duration"", n.""Instant"", n.""InstantRange"", n.""Interval"", n.""LocalDate"", n.""LocalDate2"", n.""LocalDateRange"", n.""LocalDateTime"", n.""LocalTime"", n.""Long"", n.""OffsetTime"", n.""Period"", n.""TimeZoneId"", n.""ZonedDateTime""
FROM ""NodaTimeTypes"" AS n
WHERE
n.""Instant"" AT TIME ZONE 'Europe/Berlin'
= TIMESTAMP '2018-04-20T12:31:33.666'"
);
WHERE
(n.""Instant"" AT TIME ZONE 'Europe/Berlin')
= TIMESTAMP '2018-04-20T12:31:33.666'"
);
}
[
ConditionalFact
]
...
...
@@ -1342,7 +1342,7 @@ public async Task ZonedDateTime_Date(bool async)
AssertSql
(
@"SELECT n.""Id"", n.""DateInterval"", n.""Duration"", n.""Instant"", n.""InstantRange"", n.""Interval"", n.""LocalDate"", n.""LocalDate2"", n.""LocalDateRange"", n.""LocalDateTime"", n.""LocalTime"", n.""Long"", n.""OffsetTime"", n.""Period"", n.""TimeZoneId"", n.""ZonedDateTime""
FROM ""NodaTimeTypes"" AS n
WHERE CAST(
n.""ZonedDateTime"" AT TIME ZONE 'UTC'
AS date) = DATE '2018-04-20'"
);
WHERE CAST(
(n.""ZonedDateTime"" AT TIME ZONE 'UTC')
AS date) = DATE '2018-04-20'"
);
}
[
ConditionalTheory
]
...
...
@@ -1375,7 +1375,7 @@ public async Task ZonedDateTime_LocalDateTime(bool async)
AssertSql
(
@"SELECT n.""Id"", n.""DateInterval"", n.""Duration"", n.""Instant"", n.""InstantRange"", n.""Interval"", n.""LocalDate"", n.""LocalDate2"", n.""LocalDateRange"", n.""LocalDateTime"", n.""LocalTime"", n.""Long"", n.""OffsetTime"", n.""Period"", n.""TimeZoneId"", n.""ZonedDateTime""
FROM ""NodaTimeTypes"" AS n
WHERE
n.""Instant"" AT TIME ZONE 'UTC'
= TIMESTAMP '2018-04-20T10:31:33.666'"
);
WHERE
(n.""Instant"" AT TIME ZONE 'UTC')
= TIMESTAMP '2018-04-20T10:31:33.666'"
);
}
[
ConditionalTheory
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录