1010using Microsoft . EntityFrameworkCore ;
1111using Microsoft . EntityFrameworkCore . Internal ;
1212using Microsoft . EntityFrameworkCore . Metadata ;
13- using Microsoft . EntityFrameworkCore . Metadata . Conventions . Internal ;
1413using Microsoft . EntityFrameworkCore . Metadata . Internal ;
15- using Microsoft . EntityFrameworkCore . Query . Expressions ;
16- using Microsoft . EntityFrameworkCore . Query . ExpressionVisitors ;
14+ using Microsoft . EntityFrameworkCore . Query ;
15+ using Microsoft . EntityFrameworkCore . Query . SqlExpressions ;
1716
1817namespace LinqToDB . EntityFrameworkCore
1918{
@@ -27,10 +26,10 @@ namespace LinqToDB.EntityFrameworkCore
2726 internal class EFCoreMetadataReader : IMetadataReader
2827 {
2928 readonly IModel _model ;
30- private readonly SqlTranslatingExpressionVisitorDependencies _dependencies ;
29+ private readonly RelationalSqlTranslatingExpressionVisitorDependencies _dependencies ;
3130 private readonly ConcurrentDictionary < MemberInfo , EFCoreExpressionAttribute > _calculatedExtensions = new ConcurrentDictionary < MemberInfo , EFCoreExpressionAttribute > ( ) ;
3231
33- public EFCoreMetadataReader ( IModel model , SqlTranslatingExpressionVisitorDependencies dependencies )
32+ public EFCoreMetadataReader ( IModel model , RelationalSqlTranslatingExpressionVisitorDependencies dependencies )
3433 {
3534 _model = model ;
3635 _dependencies = dependencies ;
@@ -43,8 +42,7 @@ public T[] GetAttributes<T>(Type type, bool inherit = true) where T : Attribute
4342 {
4443 if ( typeof ( T ) == typeof ( TableAttribute ) )
4544 {
46- var relational = et . Relational ( ) ;
47- return new [ ] { ( T ) ( Attribute ) new TableAttribute ( relational . TableName ) { Schema = relational . Schema } } ;
45+ return new [ ] { ( T ) ( Attribute ) new TableAttribute ( et . GetTableName ( ) ) { Schema = et . GetSchema ( ) } } ;
4846 }
4947 }
5048
@@ -76,19 +74,17 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
7674 var primaryKeyOrder = 0 ;
7775 if ( isPrimaryKey )
7876 {
79- var pk = prop . GetContainingPrimaryKey ( ) ;
77+ var pk = prop . FindContainingPrimaryKey ( ) ;
8078 primaryKeyOrder = pk . Properties . Select ( ( p , i ) => new { p , index = i } )
8179 . FirstOrDefault ( v => v . p . GetIdentifyingMemberInfo ( ) == memberInfo ) ? . index ?? 0 ;
8280 }
8381
84- var relational = prop . Relational ( ) ;
85-
8682 return new T [ ] { ( T ) ( Attribute ) new ColumnAttribute
8783 {
88- Name = relational . ColumnName ,
84+ Name = prop . GetColumnName ( ) ,
8985 Length = prop . GetMaxLength ( ) ?? 0 ,
9086 CanBeNull = prop . IsNullable ,
91- DbType = relational . ColumnType ,
87+ DbType = prop . GetColumnType ( ) ,
9288 IsPrimaryKey = isPrimaryKey ,
9389 PrimaryKeyOrder = primaryKeyOrder ,
9490 IsIdentity = prop . ValueGenerated == ValueGenerated . OnAdd ,
@@ -170,21 +166,21 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
170166 {
171167 var method = ( MethodInfo ) memberInfo ;
172168
173- var func = _model ? . Relational ( ) . DbFunctions . FirstOrDefault ( f => f . MethodInfo == method ) ;
169+ var func = _model ? . GetDbFunctions ( ) . FirstOrDefault ( f => f . MethodInfo == method ) ;
174170 if ( func != null )
175171 return new T [ ]
176172 {
177173 ( T ) ( Attribute ) new Sql . FunctionAttribute
178174 {
179- Name = func . FunctionName ,
175+ Name = func . Name ,
180176 ServerSideOnly = true
181177 }
182178 } ;
183179
184180 var functionAttributes = memberInfo . GetCustomAttributes < DbFunctionAttribute > ( inherit ) ;
185181 return functionAttributes . Select ( f => ( T ) ( Attribute ) new Sql . FunctionAttribute
186182 {
187- Name = f . FunctionName ,
183+ Name = f . Name ,
188184 ServerSideOnly = true ,
189185 } ) . ToArray ( ) ;
190186 }
@@ -214,14 +210,14 @@ private Sql.ExpressionAttribute GetDbFunctionFromMethodCall(Type type, MethodInf
214210
215211 var mcExpr = Expression . Call ( methodInfo . IsStatic ? null : objExpr , methodInfo , parametersArray ) ;
216212
217- var newExpression = _dependencies . MethodCallTranslator . Translate ( mcExpr , _model ) ;
218- if ( newExpression != null && newExpression != mcExpr )
219- {
220- if ( ! methodInfo . IsStatic )
221- parametersArray = new Expression [ ] { objExpr } . Concat ( parametersArray ) . ToArray ( ) ;
222-
223- result = ConvertToExpressionAttribute ( methodInfo , newExpression , parametersArray ) ;
224- }
213+ // var newExpression = _dependencies.MethodCallTranslatorProvider .Translate(_model, null, mcExpr, new List<SqlExpression>() );
214+ // if (newExpression != null && newExpression != mcExpr)
215+ // {
216+ // if (!methodInfo.IsStatic)
217+ // parametersArray = new Expression[] { objExpr }.Concat(parametersArray).ToArray();
218+ //
219+ // result = ConvertToExpressionAttribute(methodInfo, newExpression, parametersArray);
220+ // }
225221 }
226222
227223 return result ;
@@ -246,12 +242,12 @@ private Sql.ExpressionAttribute GetDbFunctionFromProperty(Type type, PropertyInf
246242 var objExpr = Expression . Constant ( DefaultValue . GetValue ( type ) , type ) ;
247243 var mcExpr = Expression . MakeMemberAccess ( objExpr , propInfo ) ;
248244
249- var newExpression = _dependencies . MemberTranslator . Translate ( mcExpr ) ;
250- if ( newExpression != null && newExpression != mcExpr )
251- {
252- var parametersArray = new Expression [ ] { objExpr } ;
253- result = ConvertToExpressionAttribute ( propInfo , newExpression , parametersArray ) ;
254- }
245+ // var newExpression = _dependencies.MemberTranslator.Translate(mcExpr);
246+ // if (newExpression != null && newExpression != mcExpr)
247+ // {
248+ // var parametersArray = new Expression[] { objExpr };
249+ // result = ConvertToExpressionAttribute(propInfo, newExpression, parametersArray);
250+ // }
255251 }
256252
257253 return result ;
@@ -273,9 +269,9 @@ string PrepareExpressionText(Expression expr)
273269
274270 if ( expr is SqlFunctionExpression sqlFunction )
275271 {
276- var text = sqlFunction . FunctionName ;
272+ var text = sqlFunction . Name ;
277273 if ( ! sqlFunction . Schema . IsNullOrEmpty ( ) )
278- text = sqlFunction . Schema + "." + sqlFunction . FunctionName ;
274+ text = sqlFunction . Schema + "." + sqlFunction . Name ;
279275
280276 if ( ! sqlFunction . IsNiladic )
281277 {
@@ -328,7 +324,7 @@ private static Expression UnwrapConverted(Expression expr)
328324 {
329325 if ( expr is SqlFunctionExpression func )
330326 {
331- if ( string . Equals ( func . FunctionName , "COALESCE" , StringComparison . InvariantCultureIgnoreCase ) &&
327+ if ( string . Equals ( func . Name , "COALESCE" , StringComparison . InvariantCultureIgnoreCase ) &&
332328 func . Arguments . Count == 2 && func . Arguments [ 1 ] . NodeType == ExpressionType . Default )
333329 return UnwrapConverted ( func . Arguments [ 0 ] ) ;
334330 }
0 commit comments