Skip to content

Commit 11ad626

Browse files
author
Dilshod Komilov
committed
fix
1 parent 9731199 commit 11ad626

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Microsoft.AspNet.OData.Shared/Query/Expressions/SelectExpandBinder.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,10 @@ internal Expression ProjectElement(Expression source, SelectExpandClause selectE
293293
LinqParameterContainer.Parameterize(typeof(string), _modelID) :
294294
Expression.Constant(_modelID);
295295
wrapperTypeMemberAssignments.Add(Expression.Bind(wrapperProperty, wrapperPropertyValueExpression));
296-
296+
bool instanseOfWrapperClassWasSet = false;
297297
if (IsSelectAll(selectExpandClause))
298298
{
299+
instanseOfWrapperClassWasSet = true;
299300
// Initialize property 'Instance' on the wrapper class
300301
wrapperProperty = wrapperType.GetProperty("Instance");
301302
wrapperTypeMemberAssignments.Add(Expression.Bind(wrapperProperty, source));
@@ -349,8 +350,11 @@ internal Expression ProjectElement(Expression source, SelectExpandClause selectE
349350

350351
Type wrapperGenericType = GetWrapperGenericType(isInstancePropertySet, isTypeNamePropertySet, isContainerPropertySet);
351352
wrapperType = wrapperGenericType.MakeGenericType(elementType);
352-
ConstructorInfo constructorInfo = wrapperType.GetConstructors().Single(c => c.GetParameters().Length == 1);
353-
return Expression.MemberInit(Expression.New(constructorInfo, source), wrapperTypeMemberAssignments);
353+
354+
if (instanseOfWrapperClassWasSet)
355+
return Expression.MemberInit(Expression.New(wrapperType), wrapperTypeMemberAssignments);
356+
ConstructorInfo constructorWithInstanse = wrapperType.GetConstructors().Single(c => c.GetParameters().Length == 1);
357+
return Expression.MemberInit(Expression.New(constructorWithInstanse, source), wrapperTypeMemberAssignments);
354358
}
355359

356360
/// <summary>

0 commit comments

Comments
 (0)