diff --git a/src/Microsoft.AspNet.OData.Shared/Query/Expressions/SelectExpandBinder.cs b/src/Microsoft.AspNet.OData.Shared/Query/Expressions/SelectExpandBinder.cs index 681d7c5e40..9d3cb65228 100644 --- a/src/Microsoft.AspNet.OData.Shared/Query/Expressions/SelectExpandBinder.cs +++ b/src/Microsoft.AspNet.OData.Shared/Query/Expressions/SelectExpandBinder.cs @@ -293,6 +293,7 @@ internal Expression ProjectElement(Expression source, SelectExpandClause selectE LinqParameterContainer.Parameterize(typeof(string), _modelID) : Expression.Constant(_modelID); wrapperTypeMemberAssignments.Add(Expression.Bind(wrapperProperty, wrapperPropertyValueExpression)); + if (IsSelectAll(selectExpandClause)) { // Initialize property 'Instance' on the wrapper class @@ -345,11 +346,16 @@ internal Expression ProjectElement(Expression source, SelectExpandClause selectE } } } + if (isInstancePropertySet) + { + Type wrapperGenericType = GetWrapperGenericType(isInstancePropertySet, isTypeNamePropertySet, isContainerPropertySet); + wrapperType = wrapperGenericType.MakeGenericType(elementType); + return Expression.MemberInit(Expression.New(wrapperType), wrapperTypeMemberAssignments); + } + ConstructorInfo constructorWithInstanse = wrapperType.GetConstructors().Single(c => c.GetParameters().Length == 1); + return Expression.MemberInit(Expression.New(constructorWithInstanse, source), wrapperTypeMemberAssignments); - Type wrapperGenericType = GetWrapperGenericType(isInstancePropertySet, isTypeNamePropertySet, isContainerPropertySet); - wrapperType = wrapperGenericType.MakeGenericType(elementType); - return Expression.MemberInit(Expression.New(wrapperType), wrapperTypeMemberAssignments); } /// @@ -1243,54 +1249,18 @@ property selection combination possible. */ private class SelectAllAndExpand : SelectExpandWrapper { - public SelectAllAndExpand(TEntity entity) : base(entity) - { - - } - - public SelectAllAndExpand() - { - - } } private class SelectAll : SelectExpandWrapper { - public SelectAll(TEntity entity) : base(entity) - { - - } - - public SelectAll() - { - - } } private class SelectSomeAndInheritance : SelectExpandWrapper { - public SelectSomeAndInheritance(TEntity entity) : base(entity) - { - - } - - public SelectSomeAndInheritance() - { - - } } private class SelectSome : SelectAllAndExpand { - public SelectSome(TEntity entity) : base(entity) - { - - } - - public SelectSome() - { - - } } } }