@@ -1487,6 +1487,26 @@ protected override MemberAssignment VisitMemberAssignment(MemberAssignment assig
14871487 return assignment ;
14881488 }
14891489
1490+ protected override Expression VisitConditional ( ConditionalExpression c ) // a.IsNew
1491+ {
1492+ Expression test = this . Visit ( c . Test ) ;
1493+ if ( test is ConstantExpression co )
1494+ {
1495+ if ( ( bool ) co . Value ! )
1496+ return this . Visit ( c . IfTrue ) ;
1497+ else
1498+ return this . Visit ( c . IfFalse ) ;
1499+ }
1500+
1501+ Expression ifTrue = this . Visit ( c . IfTrue ) ;
1502+ Expression ifFalse = this . Visit ( c . IfFalse ) ;
1503+ if ( test != c . Test || ifTrue != c . IfTrue || ifFalse != c . IfFalse )
1504+ {
1505+ return Expression . Condition ( test , ifTrue , ifFalse ) ;
1506+ }
1507+ return c ;
1508+ }
1509+
14901510 protected override Expression VisitMember ( MemberExpression m )
14911511 {
14921512 Expression ex = base . VisitMember ( m ) ;
@@ -1539,6 +1559,7 @@ public Expression BindMethodCall(MethodCallExpression m)
15391559 return result ;
15401560 }
15411561
1562+
15421563 if ( source is ImplementedByExpression ib )
15431564 {
15441565 if ( m . Method . IsExtensionMethod ( ) )
@@ -1625,9 +1646,39 @@ public Expression BindMethodCall(MethodCallExpression m)
16251646 return tablePeriod ;
16261647 }
16271648
1649+ Expression PartialEval ( Expression ee )
1650+ {
1651+ if ( m . Method . IsExtensionMethod ( ) )
1652+ {
1653+ return ExpressionEvaluator . PartialEval ( Expression . Call ( null , m . Method , m . Arguments . Skip ( 1 ) . PreAnd ( ee ) ) ) ;
1654+ }
1655+ else
1656+ {
1657+ return ExpressionEvaluator . PartialEval ( Expression . Call ( ee , m . Method , m . Arguments ) ) ;
1658+ }
1659+ }
1660+
1661+ if ( source is TypeEntityExpression type )
1662+ {
1663+ return Condition ( Expression . NotEqual ( type . ExternalId , NullId ( type . ExternalId . ValueType ) ) ,
1664+ ifTrue : PartialEval ( Expression . Constant ( type . TypeValue ) ) ,
1665+ ifFalse : Expression . Constant ( null , m . Type ) ) ;
1666+ }
1667+
1668+ if ( source is TypeImplementedByExpression typeIB )
1669+ {
1670+ return typeIB . TypeImplementations . Aggregate (
1671+ ( Expression ) Expression . Constant ( null , m . Type ) ,
1672+ ( acum , kvp ) => Condition ( Expression . NotEqual ( kvp . Value , NullId ( kvp . Value . Value . Type ) ) ,
1673+ ifTrue : PartialEval ( Expression . Constant ( kvp . Key ) ) ,
1674+ ifFalse : acum ) ) ;
1675+ }
1676+
16281677 return m ;
16291678 }
16301679
1680+
1681+
16311682
16321683 private ConditionalExpression DispatchConditional ( MethodCallExpression m , Expression test , Expression ifTrue , Expression ifFalse )
16331684 {
@@ -1748,6 +1799,9 @@ public Expression BindMemberAccess(MemberExpression m)
17481799 if ( pi != null && ReflectionTools . PropertyEquals ( pi , EntityExpression . IdOrNullProperty ) )
17491800 return ee . ExternalId ;
17501801
1802+ if ( m . Member . Name == nameof ( Entity . IsNew ) )
1803+ return Expression . Constant ( false ) ;
1804+
17511805 FieldInfo ? fi = m . Member as FieldInfo ?? Reflector . TryFindFieldInfo ( ee . Type , pi ! ) ;
17521806
17531807 if ( fi == null )
@@ -1862,6 +1916,25 @@ public Expression BindMemberAccess(MemberExpression m)
18621916 _ => throw new InvalidOperationException ( "The member {0} of MListElement is not accesible on queries" . FormatWith ( m . Member ) ) ,
18631917 } ;
18641918 }
1919+ case DbExpressionType . TypeEntity :
1920+ {
1921+ TypeEntityExpression type = ( TypeEntityExpression ) source ;
1922+
1923+ return Condition ( Expression . NotEqual ( type . ExternalId , NullId ( type . ExternalId . ValueType ) ) ,
1924+ ifTrue : ExpressionEvaluator . PartialEval ( Expression . MakeMemberAccess ( Expression . Constant ( type . TypeValue ) , m . Member ) ) ,
1925+ ifFalse : Expression . Constant ( null , m . Type ) ) ;
1926+ }
1927+
1928+ case DbExpressionType . TypeImplementedBy :
1929+ {
1930+ TypeImplementedByExpression typeIB = ( TypeImplementedByExpression ) source ;
1931+
1932+ return typeIB . TypeImplementations . Aggregate (
1933+ ( Expression ) Expression . Constant ( null , m . Type ) ,
1934+ ( acum , kvp ) => Condition ( Expression . NotEqual ( kvp . Value , NullId ( kvp . Value . Value . Type ) ) ,
1935+ ifTrue : ExpressionEvaluator . PartialEval ( Expression . MakeMemberAccess ( Expression . Constant ( kvp . Key ) , m . Member ) ) ,
1936+ ifFalse : acum ) ) ;
1937+ }
18651938 }
18661939 }
18671940 break ;
@@ -3477,6 +3550,7 @@ protected override Expression VisitConditional(ConditionalExpression c)
34773550 var ifTrue = Visit ( c . IfTrue ) ;
34783551 var ifFalse = Visit ( c . IfFalse ) ;
34793552
3553+
34803554 if ( colExpression is LiteReferenceExpression )
34813555 {
34823556 return Combiner < LiteReferenceExpression > ( ifTrue , ifFalse , ( col , l , r ) =>
0 commit comments