Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Efcore.Pg
提交
36376107
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,发现更多精彩内容 >>
未验证
提交
36376107
编写于
5月 17, 2022
作者:
S
Shay Rojansky
提交者:
GitHub
5月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Translate ValueTuple.Create() (#2371)
As a nicer alternative to new ValueTuple<T1, T2>(...)
上级
4de9b541
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
54 addition
and
27 deletion
+54
-27
src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMethodCallTranslatorProvider.cs
...ranslators/Internal/NpgsqlMethodCallTranslatorProvider.cs
+1
-1
src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRowValueTranslator.cs
...xpressionTranslators/Internal/NpgsqlRowValueTranslator.cs
+14
-5
src/EFCore.PG/Query/Internal/NpgsqlEvaluatableExpressionFilter.cs
...re.PG/Query/Internal/NpgsqlEvaluatableExpressionFilter.cs
+6
-3
test/EFCore.PG.FunctionalTests/Query/NorthwindWhereQueryNpgsqlTest.cs
...PG.FunctionalTests/Query/NorthwindWhereQueryNpgsqlTest.cs
+33
-18
未找到文件。
src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlMethodCallTranslatorProvider.cs
浏览文件 @
36376107
...
...
@@ -37,7 +37,7 @@ public class NpgsqlMethodCallTranslatorProvider : RelationalMethodCallTranslator
new
NpgsqlRandomTranslator
(
sqlExpressionFactory
),
new
NpgsqlRangeTranslator
(
typeMappingSource
,
sqlExpressionFactory
,
model
),
new
NpgsqlRegexIsMatchTranslator
(
sqlExpressionFactory
),
new
NpgsqlRowValue
Comparison
Translator
(
sqlExpressionFactory
),
new
NpgsqlRowValueTranslator
(
sqlExpressionFactory
),
new
NpgsqlStringMethodTranslator
(
typeMappingSource
,
sqlExpressionFactory
,
model
),
new
NpgsqlTrigramsMethodTranslator
(
typeMappingSource
,
sqlExpressionFactory
,
model
),
});
...
...
src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRowValue
Comparison
Translator.cs
→
src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlRowValueTranslator.cs
浏览文件 @
36376107
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using
System.Diagnostics.CodeAnalysis
;
using
System.Runtime.CompilerServices
;
using
Npgsql.EntityFrameworkCore.PostgreSQL.Internal
;
using
Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal
;
namespace
Npgsql.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal
;
public
class
NpgsqlRowValue
Comparison
Translator
:
IMethodCallTranslator
public
class
NpgsqlRowValueTranslator
:
IMethodCallTranslator
{
private
readonly
NpgsqlSqlExpressionFactory
_sqlExpressionFactory
;
...
...
@@ -28,7 +29,7 @@ public class NpgsqlRowValueComparisonTranslator : IMethodCallTranslator
typeof
(
NpgsqlDbFunctionsExtensions
).
GetMethods
()
.
Single
(
m
=>
m
.
Name
==
nameof
(
NpgsqlDbFunctionsExtensions
.
LessThanOrEqual
));
private
static
readonly
Dictionary
<
MethodInfo
,
ExpressionType
>
Methods
=
new
()
private
static
readonly
Dictionary
<
MethodInfo
,
ExpressionType
>
Comparison
Methods
=
new
()
{
{
GreaterThan
,
ExpressionType
.
GreaterThan
},
{
LessThan
,
ExpressionType
.
LessThan
},
...
...
@@ -37,19 +38,27 @@ public class NpgsqlRowValueComparisonTranslator : IMethodCallTranslator
};
/// <summary>
/// Initializes a new instance of the <see cref="NpgsqlRowValue
Comparison
Translator"/> class.
/// Initializes a new instance of the <see cref="NpgsqlRowValueTranslator"/> class.
/// </summary>
public
NpgsqlRowValue
Comparison
Translator
(
NpgsqlSqlExpressionFactory
sqlExpressionFactory
)
public
NpgsqlRowValueTranslator
(
NpgsqlSqlExpressionFactory
sqlExpressionFactory
)
=>
_sqlExpressionFactory
=
sqlExpressionFactory
;
/// <inheritdoc />
[
DynamicDependency
(
DynamicallyAccessedMemberTypes
.
PublicMethods
,
typeof
(
ValueType
))]
// For ValueTuple.Create
public
virtual
SqlExpression
?
Translate
(
SqlExpression
?
instance
,
MethodInfo
method
,
IReadOnlyList
<
SqlExpression
>
arguments
,
IDiagnosticsLogger
<
DbLoggerCategory
.
Query
>
logger
)
{
if
(
method
.
DeclaringType
!=
typeof
(
NpgsqlDbFunctionsExtensions
)
||
!
Methods
.
TryGetValue
(
method
,
out
var
expressionType
))
// Translate ValueTuple.Create
if
(
method
.
DeclaringType
==
typeof
(
ValueTuple
)
&&
method
.
IsStatic
&&
method
.
Name
==
nameof
(
ValueTuple
.
Create
))
{
return
new
PostgresRowValueExpression
(
arguments
,
method
.
ReturnType
);
}
// Translate EF.Functions.GreaterThan and other comparisons
if
(
method
.
DeclaringType
!=
typeof
(
NpgsqlDbFunctionsExtensions
)
||
!
ComparisonMethods
.
TryGetValue
(
method
,
out
var
expressionType
))
{
return
null
;
}
...
...
src/EFCore.PG/Query/Internal/NpgsqlEvaluatableExpressionFilter.cs
浏览文件 @
36376107
...
...
@@ -23,15 +23,18 @@ public override bool IsEvaluatableExpression(Expression expression, IModel model
{
case
MethodCallExpression
methodCallExpression
:
var
declaringType
=
methodCallExpression
.
Method
.
DeclaringType
;
var
method
=
methodCallExpression
.
Method
;
if
(
method
CallExpression
.
Method
==
TsQueryParse
||
method
CallExpression
.
Method
==
TsVectorParse
if
(
method
==
TsQueryParse
||
method
==
TsVectorParse
||
declaringType
==
typeof
(
NpgsqlDbFunctionsExtensions
)
||
declaringType
==
typeof
(
NpgsqlFullTextSearchDbFunctionsExtensions
)
||
declaringType
==
typeof
(
NpgsqlFullTextSearchLinqExtensions
)
||
declaringType
==
typeof
(
NpgsqlNetworkDbFunctionsExtensions
)
||
declaringType
==
typeof
(
NpgsqlJsonDbFunctionsExtensions
)
||
declaringType
==
typeof
(
NpgsqlRangeDbFunctionsExtensions
))
||
declaringType
==
typeof
(
NpgsqlRangeDbFunctionsExtensions
)
// Prevent evaluation of ValueTuple.Create, see NewExpression of ITuple below
||
declaringType
==
typeof
(
ValueTuple
)
&&
method
.
Name
==
nameof
(
ValueTuple
.
Create
))
{
return
false
;
}
...
...
test/EFCore.PG.FunctionalTests/Query/NorthwindWhereQueryNpgsqlTest.cs
浏览文件 @
36376107
...
...
@@ -245,8 +245,8 @@ public async Task Row_value_GreaterThan()
_
=
await
ctx
.
Customers
.
Where
(
c
=>
EF
.
Functions
.
GreaterThan
(
new
ValueTuple
<
string
,
string
>
(
c
.
City
,
c
.
CustomerID
),
new
ValueTuple
<
string
,
string
>
(
"Buenos Aires"
,
"OCEAN"
)))
ValueTuple
.
Create
(
c
.
City
,
c
.
CustomerID
),
ValueTuple
.
Create
(
"Buenos Aires"
,
"OCEAN"
)))
.
CountAsync
();
AssertSql
(
...
...
@@ -262,8 +262,8 @@ public async Task Row_value_GreaterThan_with_differing_types()
_
=
await
ctx
.
Orders
.
Where
(
o
=>
EF
.
Functions
.
GreaterThan
(
new
ValueTuple
<
string
,
int
>
(
o
.
CustomerID
,
o
.
OrderID
),
new
ValueTuple
<
string
,
int
>
(
"ALFKI"
,
10702
)))
ValueTuple
.
Create
(
o
.
CustomerID
,
o
.
OrderID
),
ValueTuple
.
Create
(
"ALFKI"
,
10702
)))
.
CountAsync
();
AssertSql
(
...
...
@@ -281,8 +281,8 @@ public async Task Row_value_GreaterThan_with_parameter()
_
=
await
ctx
.
Customers
.
Where
(
c
=>
EF
.
Functions
.
GreaterThan
(
new
ValueTuple
<
string
,
string
>
(
c
.
City
,
c
.
CustomerID
),
new
ValueTuple
<
string
,
string
>
(
city1
,
"OCEAN"
)))
ValueTuple
.
Create
(
c
.
City
,
c
.
CustomerID
),
ValueTuple
.
Create
(
city1
,
"OCEAN"
)))
.
CountAsync
();
AssertSql
(
...
...
@@ -300,8 +300,8 @@ public async Task Row_value_LessThan()
_
=
await
ctx
.
Customers
.
Where
(
c
=>
EF
.
Functions
.
LessThan
(
new
ValueTuple
<
string
,
string
>
(
c
.
City
,
c
.
CustomerID
),
new
ValueTuple
<
string
,
string
>
(
"Buenos Aires"
,
"OCEAN"
)))
ValueTuple
.
Create
(
c
.
City
,
c
.
CustomerID
),
ValueTuple
.
Create
(
"Buenos Aires"
,
"OCEAN"
)))
.
CountAsync
();
AssertSql
(
...
...
@@ -317,8 +317,8 @@ public async Task Row_value_GreaterThanOrEqual()
_
=
await
ctx
.
Customers
.
Where
(
c
=>
EF
.
Functions
.
GreaterThanOrEqual
(
new
ValueTuple
<
string
,
string
>
(
c
.
City
,
c
.
CustomerID
),
new
ValueTuple
<
string
,
string
>
(
"Buenos Aires"
,
"OCEAN"
)))
ValueTuple
.
Create
(
c
.
City
,
c
.
CustomerID
),
ValueTuple
.
Create
(
"Buenos Aires"
,
"OCEAN"
)))
.
CountAsync
();
AssertSql
(
...
...
@@ -334,6 +334,23 @@ public async Task Row_value_LessThanOrEqual()
_
=
await
ctx
.
Customers
.
Where
(
c
=>
EF
.
Functions
.
LessThanOrEqual
(
ValueTuple
.
Create
(
c
.
City
,
c
.
CustomerID
),
ValueTuple
.
Create
(
"Buenos Aires"
,
"OCEAN"
)))
.
CountAsync
();
AssertSql
(
@"SELECT COUNT(*)::INT
FROM ""Customers"" AS c
WHERE (c.""City"", c.""CustomerID"") <= ('Buenos Aires', 'OCEAN')"
);
}
[
ConditionalFact
]
public
async
Task
Row_value_with_ValueTuple_constructor
()
{
await
using
var
ctx
=
CreateContext
();
_
=
await
ctx
.
Customers
.
Where
(
c
=>
EF
.
Functions
.
GreaterThan
(
new
ValueTuple
<
string
,
string
>(
c
.
City
,
c
.
CustomerID
),
new
ValueTuple
<
string
,
string
>(
"Buenos Aires"
,
"OCEAN"
)))
.
CountAsync
();
...
...
@@ -341,7 +358,7 @@ public async Task Row_value_LessThanOrEqual()
AssertSql
(
@"SELECT COUNT(*)::INT
FROM ""Customers"" AS c
WHERE (c.""City"", c.""CustomerID"")
<=
('Buenos Aires', 'OCEAN')"
);
WHERE (c.""City"", c.""CustomerID"")
>
('Buenos Aires', 'OCEAN')"
);
}
[
ConditionalFact
]
...
...
@@ -352,8 +369,8 @@ public async Task Row_value_parameter_count_mismatch()
var
exception
=
await
Assert
.
ThrowsAsync
<
ArgumentException
>(
()
=>
ctx
.
Customers
.
Where
(
c
=>
EF
.
Functions
.
LessThanOrEqual
(
new
ValueTuple
<
string
,
string
>
(
c
.
City
,
c
.
CustomerID
),
new
ValueTuple
<
string
,
string
,
string
>
(
"Buenos Aires"
,
"OCEAN"
,
"foo"
)))
ValueTuple
.
Create
(
c
.
City
,
c
.
CustomerID
),
ValueTuple
.
Create
(
"Buenos Aires"
,
"OCEAN"
,
"foo"
)))
.
CountAsync
());
Assert
.
Equal
(
NpgsqlStrings
.
RowValueComparisonRequiresTuplesOfSameLength
,
exception
.
Message
);
...
...
@@ -366,8 +383,8 @@ public async Task Row_value_equals()
_
=
await
ctx
.
Customers
.
Where
(
c
=>
new
ValueTuple
<
string
,
string
>
(
c
.
City
,
c
.
CustomerID
).
Equals
(
new
ValueTuple
<
string
,
string
>
(
"Buenos Aires"
,
"OCEAN"
)))
ValueTuple
.
Create
(
c
.
City
,
c
.
CustomerID
).
Equals
(
ValueTuple
.
Create
(
"Buenos Aires"
,
"OCEAN"
)))
.
CountAsync
();
AssertSql
(
...
...
@@ -382,9 +399,7 @@ public async Task Row_value_not_equals()
await
using
var
ctx
=
CreateContext
();
_
=
await
ctx
.
Customers
.
Where
(
c
=>
!
new
ValueTuple
<
string
,
string
>(
c
.
City
,
c
.
CustomerID
).
Equals
(
new
ValueTuple
<
string
,
string
>(
"Buenos Aires"
,
"OCEAN"
)))
.
Where
(
c
=>
!
ValueTuple
.
Create
(
c
.
City
,
c
.
CustomerID
).
Equals
(
ValueTuple
.
Create
(
"Buenos Aires"
,
"OCEAN"
)))
.
CountAsync
();
AssertSql
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录