@@ -2192,9 +2192,11 @@ private object SetAnonTypePropertyNamesForSelectExpression(object expr, Expressi
21922192 return new PartialSqlString ( OrmLiteUtils . UnquotedColumnName ( strExpr ) != member . Name
21932193 ? strExpr + " AS " + member . Name
21942194 : strExpr ) ;
2195- }
2195+ }
21962196
2197- return UseSelectPropertiesAsAliases
2197+ var usePropertyAlias = UseSelectPropertiesAsAliases ||
2198+ ( expr is PartialSqlString p && Equals ( p , PartialSqlString . Null ) ) ; // new { Alias = (DateTime?)null }
2199+ return usePropertyAlias
21982200 ? new SelectItemExpression ( DialectProvider , expr . ToString ( ) , member . Name )
21992201 : expr ;
22002202 }
@@ -2256,7 +2258,7 @@ protected virtual object VisitParameter(ParameterExpression p)
22562258 protected virtual object VisitConstant ( ConstantExpression c )
22572259 {
22582260 if ( c . Value == null )
2259- return new PartialSqlString ( "null" ) ;
2261+ return PartialSqlString . Null ;
22602262
22612263 return c . Value ;
22622264 }
@@ -3049,12 +3051,24 @@ public interface IHasDialectProvider
30493051
30503052 public class PartialSqlString
30513053 {
3054+ public static PartialSqlString Null = new ( "null" ) ;
3055+
30523056 public PartialSqlString ( string text )
30533057 {
30543058 Text = text ;
30553059 }
30563060 public string Text { get ; internal set ; }
30573061 public override string ToString ( ) => Text ;
3062+
3063+ protected bool Equals ( PartialSqlString other ) => Text == other . Text ;
3064+ public override bool Equals ( object obj )
3065+ {
3066+ if ( ReferenceEquals ( null , obj ) ) return false ;
3067+ if ( ReferenceEquals ( this , obj ) ) return true ;
3068+ if ( obj . GetType ( ) != this . GetType ( ) ) return false ;
3069+ return Equals ( ( PartialSqlString ) obj ) ;
3070+ }
3071+ public override int GetHashCode ( ) => ( Text != null ? Text . GetHashCode ( ) : 0 ) ;
30583072 }
30593073
30603074 public class EnumMemberAccess : PartialSqlString
0 commit comments