@@ -124,7 +124,16 @@ public virtual Expression Translate(SelectExpression selectExpression, Expressio
124124 return _selectExpression . GetProjection ( projectionBindingExpression ) switch
125125 {
126126 StructuralTypeProjectionExpression projection => AddClientProjection ( projection , typeof ( ValueBuffer ) ) ,
127- SqlExpression mappedSqlExpression => AddClientProjection ( mappedSqlExpression , expression . Type ) ,
127+ SqlExpression mappedSqlExpression => AddClientProjection (
128+ mappedSqlExpression ,
129+ ( mappedSqlExpression switch
130+ {
131+ ColumnExpression c => c . IsNullable ,
132+ SqlFunctionExpression f => f . IsNullable ,
133+ _ => mappedSqlExpression . Type . IsNullableType ( )
134+ } )
135+ ? expression . Type . MakeNullable ( )
136+ : expression . Type ) ,
128137 _ => throw new InvalidOperationException ( CoreStrings . TranslationFailed ( projectionBindingExpression . Print ( ) ) )
129138 } ;
130139
@@ -234,8 +243,19 @@ public virtual Expression Translate(SelectExpression selectExpression, Expressio
234243 {
235244 case SqlExpression sqlExpression :
236245 _projectionMapping [ _projectionMembers . Peek ( ) ] = sqlExpression ;
246+
247+ // فحص ذكي للـ Nullability يغطي العمود والدالة وأي تعبير آخر
248+ var isNullable = sqlExpression switch
249+ {
250+ ColumnExpression c => c . IsNullable ,
251+ SqlFunctionExpression f => f . IsNullable ,
252+ _ => sqlExpression . Type . IsNullableType ( )
253+ } ;
254+
237255 return new ProjectionBindingExpression (
238- _selectExpression , _projectionMembers . Peek ( ) , expression . Type ) ;
256+ _selectExpression ,
257+ _projectionMembers . Peek ( ) ,
258+ isNullable ? expression . Type . MakeNullable ( ) : expression . Type ) ;
239259
240260 // This handles the case of a complex type being projected out of a Select.
241261 // Note that an entity type being projected is (currently) handled differently
0 commit comments