1- using System . Security . AccessControl ;
2- using Npgsql . EntityFrameworkCore . PostgreSQL . Query . Expressions ;
1+ using Npgsql . EntityFrameworkCore . PostgreSQL . Query . Expressions ;
2+ using static Npgsql . EntityFrameworkCore . PostgreSQL . Utilities . Statics ;
33
44namespace Npgsql . EntityFrameworkCore . PostgreSQL . Query . ExpressionTranslators . Internal ;
55
@@ -9,7 +9,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Inte
99/// any release. You should only use it directly in your code with extreme caution and knowing that
1010/// doing so can result in application failures when updating to a new Entity Framework Core release.
1111/// </summary>
12- public class NpgsqlCubeTranslator : IMethodCallTranslator
12+ public class NpgsqlCubeTranslator : IMethodCallTranslator , IMemberTranslator
1313{
1414 private readonly NpgsqlSqlExpressionFactory _sqlExpressionFactory ;
1515
@@ -31,30 +31,115 @@ public NpgsqlCubeTranslator(NpgsqlSqlExpressionFactory sqlExpressionFactory)
3131 IReadOnlyList < SqlExpression > arguments ,
3232 IDiagnosticsLogger < DbLoggerCategory . Query > logger )
3333 {
34- if ( method . DeclaringType ! = typeof ( NpgsqlCubeDbFunctionsExtensions ) )
34+ if ( method . DeclaringType = = typeof ( NpgsqlCubeDbFunctionsExtensions ) )
3535 {
36- return null ;
36+ return method . Name switch
37+ {
38+ nameof ( NpgsqlCubeDbFunctionsExtensions . Overlaps )
39+ => _sqlExpressionFactory . Overlaps ( arguments [ 0 ] , arguments [ 1 ] ) ,
40+ nameof ( NpgsqlCubeDbFunctionsExtensions . Contains )
41+ => _sqlExpressionFactory . Contains ( arguments [ 0 ] , arguments [ 1 ] ) ,
42+ nameof ( NpgsqlCubeDbFunctionsExtensions . ContainedBy )
43+ => _sqlExpressionFactory . ContainedBy ( arguments [ 0 ] , arguments [ 1 ] ) ,
44+ nameof ( NpgsqlCubeDbFunctionsExtensions . NthCoordinate )
45+ => _sqlExpressionFactory . MakePostgresBinary ( PostgresExpressionType . CubeNthCoordinate , arguments [ 0 ] , arguments [ 1 ] ) ,
46+ nameof ( NpgsqlCubeDbFunctionsExtensions . NthCoordinate2 )
47+ => _sqlExpressionFactory . MakePostgresBinary ( PostgresExpressionType . CubeNthCoordinate2 , arguments [ 0 ] , arguments [ 1 ] ) ,
48+ nameof ( NpgsqlCubeDbFunctionsExtensions . Distance )
49+ => _sqlExpressionFactory . MakePostgresBinary ( PostgresExpressionType . Distance , arguments [ 0 ] , arguments [ 1 ] ) ,
50+ nameof ( NpgsqlCubeDbFunctionsExtensions . DistanceTaxicab )
51+ => _sqlExpressionFactory . MakePostgresBinary ( PostgresExpressionType . CubeDistanceTaxicab , arguments [ 0 ] , arguments [ 1 ] ) ,
52+ nameof ( NpgsqlCubeDbFunctionsExtensions . DistanceChebyshev )
53+ => _sqlExpressionFactory . MakePostgresBinary ( PostgresExpressionType . CubeDistanceChebyshev , arguments [ 0 ] , arguments [ 1 ] ) ,
54+ nameof ( NpgsqlCubeDbFunctionsExtensions . Union )
55+ => _sqlExpressionFactory . Function (
56+ "cube_union" ,
57+ new [ ] { arguments [ 0 ] , arguments [ 1 ] } ,
58+ nullable : true ,
59+ argumentsPropagateNullability : TrueArrays [ 2 ] ,
60+ method . ReturnType ) ,
61+ nameof ( NpgsqlCubeDbFunctionsExtensions . Intersect )
62+ => _sqlExpressionFactory . Function (
63+ "cube_inter" ,
64+ new [ ] { arguments [ 0 ] , arguments [ 1 ] } ,
65+ nullable : true ,
66+ argumentsPropagateNullability : TrueArrays [ 2 ] ,
67+ method . ReturnType ) ,
68+ nameof ( NpgsqlCubeDbFunctionsExtensions . Enlarge )
69+ => _sqlExpressionFactory . Function (
70+ "cube_enlarge" ,
71+ new [ ] { arguments [ 0 ] , arguments [ 1 ] , arguments [ 2 ] } ,
72+ nullable : true ,
73+ argumentsPropagateNullability : TrueArrays [ 3 ] ,
74+ method . ReturnType ) ,
75+
76+ _ => null
77+ } ;
3778 }
3879
39- return method . Name switch
80+ if ( method . DeclaringType == typeof ( NpgsqlCube ) && instance != null )
4081 {
41- nameof ( NpgsqlCubeDbFunctionsExtensions . Overlaps )
42- => _sqlExpressionFactory . Overlaps ( arguments [ 0 ] , arguments [ 1 ] ) ,
43- nameof ( NpgsqlCubeDbFunctionsExtensions . Contains )
44- => _sqlExpressionFactory . Contains ( arguments [ 0 ] , arguments [ 1 ] ) ,
45- nameof ( NpgsqlCubeDbFunctionsExtensions . ContainedBy )
46- => _sqlExpressionFactory . ContainedBy ( arguments [ 0 ] , arguments [ 1 ] ) ,
47- nameof ( NpgsqlCubeDbFunctionsExtensions . NthCoordinate )
48- => _sqlExpressionFactory . MakePostgresBinary ( PostgresExpressionType . CubeNthCoordinate , arguments [ 0 ] , arguments [ 1 ] ) ,
49- nameof ( NpgsqlCubeDbFunctionsExtensions . NthCoordinate2 )
50- => _sqlExpressionFactory . MakePostgresBinary ( PostgresExpressionType . CubeNthCoordinate2 , arguments [ 0 ] , arguments [ 1 ] ) ,
51- nameof ( NpgsqlCubeDbFunctionsExtensions . Distance )
52- => _sqlExpressionFactory . MakePostgresBinary ( PostgresExpressionType . Distance , arguments [ 0 ] , arguments [ 1 ] ) ,
53- nameof ( NpgsqlCubeDbFunctionsExtensions . DistanceTaxicab )
54- => _sqlExpressionFactory . MakePostgresBinary ( PostgresExpressionType . CubeDistanceTaxicab , arguments [ 0 ] , arguments [ 1 ] ) ,
55- nameof ( NpgsqlCubeDbFunctionsExtensions . DistanceChebyshev )
56- => _sqlExpressionFactory . MakePostgresBinary ( PostgresExpressionType . CubeDistanceChebyshev , arguments [ 0 ] , arguments [ 1 ] ) ,
82+ return method . Name switch
83+ {
84+ nameof ( NpgsqlCube . LlCoord )
85+ => _sqlExpressionFactory . Function (
86+ "cube_ll_coord" ,
87+ new [ ] { instance , arguments [ 0 ] } ,
88+ nullable : true ,
89+ argumentsPropagateNullability : TrueArrays [ 2 ] ,
90+ method . ReturnType ) ,
91+ nameof ( NpgsqlCube . UrCoord )
92+ => _sqlExpressionFactory . Function (
93+ "cube_ur_coord" ,
94+ new [ ] { instance , arguments [ 0 ] } ,
95+ nullable : true ,
96+ argumentsPropagateNullability : TrueArrays [ 2 ] ,
97+ method . ReturnType ) ,
98+ nameof ( NpgsqlCube . Subset )
99+ => _sqlExpressionFactory . Function (
100+ "cube_subset" ,
101+ new [ ] { instance , arguments [ 0 ] } ,
102+ nullable : true ,
103+ argumentsPropagateNullability : TrueArrays [ 2 ] ,
104+ method . ReturnType ) ,
105+
106+ _ => null
107+ } ;
108+ }
109+
110+ // TODO: Implement indexing into lower/upper lists with cube_ll_coord and cube_ur_coord
57111
112+ return null ;
113+ }
114+
115+ /// <inheritdoc />
116+ public SqlExpression ? Translate (
117+ SqlExpression ? instance ,
118+ MemberInfo member ,
119+ Type returnType ,
120+ IDiagnosticsLogger < DbLoggerCategory . Query > logger )
121+ {
122+ if ( member . DeclaringType != typeof ( NpgsqlCube ) || instance == null )
123+ {
124+ return null ;
125+ }
126+
127+ return member . Name switch
128+ {
129+ nameof ( NpgsqlCube . Dimensions )
130+ => _sqlExpressionFactory . Function (
131+ "cube_dim" ,
132+ new [ ] { instance } ,
133+ nullable : true ,
134+ argumentsPropagateNullability : TrueArrays [ 1 ] ,
135+ returnType ) ,
136+ nameof ( NpgsqlCube . Point )
137+ => _sqlExpressionFactory . Function (
138+ "cube_is_point" ,
139+ new [ ] { instance } ,
140+ nullable : true ,
141+ argumentsPropagateNullability : TrueArrays [ 1 ] ,
142+ returnType ) ,
58143 _ => null
59144 } ;
60145 }
0 commit comments