-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MissingMethodException on getting ResourceInstance from ODataResourceSerializer #2558
base: master
Are you sure you want to change the base?
Changes from 7 commits
66f7720
c85d30f
a1855f0
ed8c561
5aee3d0
9731199
11ad626
119f2a9
dfb9bac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,9 +293,10 @@ internal Expression ProjectElement(Expression source, SelectExpandClause selectE | |
LinqParameterContainer.Parameterize(typeof(string), _modelID) : | ||
Expression.Constant(_modelID); | ||
wrapperTypeMemberAssignments.Add(Expression.Bind(wrapperProperty, wrapperPropertyValueExpression)); | ||
|
||
bool instanseOfWrapperClassWasSet = false; | ||
if (IsSelectAll(selectExpandClause)) | ||
{ | ||
instanseOfWrapperClassWasSet = true; | ||
// Initialize property 'Instance' on the wrapper class | ||
wrapperProperty = wrapperType.GetProperty("Instance"); | ||
wrapperTypeMemberAssignments.Add(Expression.Bind(wrapperProperty, source)); | ||
|
@@ -349,7 +350,11 @@ internal Expression ProjectElement(Expression source, SelectExpandClause selectE | |
|
||
Type wrapperGenericType = GetWrapperGenericType(isInstancePropertySet, isTypeNamePropertySet, isContainerPropertySet); | ||
wrapperType = wrapperGenericType.MakeGenericType(elementType); | ||
return Expression.MemberInit(Expression.New(wrapperType), wrapperTypeMemberAssignments); | ||
|
||
if (instanseOfWrapperClassWasSet) | ||
return Expression.MemberInit(Expression.New(wrapperType), wrapperTypeMemberAssignments); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as per code guidelines, please enclose body of conditional in braces (even if it's a single line). Improves code readability and reduces introducing logical errors later. |
||
ConstructorInfo constructorWithInstanse = wrapperType.GetConstructors().Single(c => c.GetParameters().Length == 1); | ||
return Expression.MemberInit(Expression.New(constructorWithInstanse, source), wrapperTypeMemberAssignments); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -1243,18 +1248,54 @@ property selection combination possible. */ | |
|
||
private class SelectAllAndExpand<TEntity> : SelectExpandWrapper<TEntity> | ||
{ | ||
public SelectAllAndExpand(TEntity entity) : base(entity) | ||
{ | ||
|
||
} | ||
|
||
public SelectAllAndExpand() | ||
{ | ||
|
||
} | ||
} | ||
|
||
private class SelectAll<TEntity> : SelectExpandWrapper<TEntity> | ||
{ | ||
public SelectAll(TEntity entity) : base(entity) | ||
{ | ||
|
||
} | ||
|
||
public SelectAll() | ||
{ | ||
|
||
} | ||
} | ||
|
||
private class SelectSomeAndInheritance<TEntity> : SelectExpandWrapper<TEntity> | ||
{ | ||
public SelectSomeAndInheritance(TEntity entity) : base(entity) | ||
{ | ||
|
||
} | ||
|
||
public SelectSomeAndInheritance() | ||
{ | ||
|
||
} | ||
} | ||
|
||
private class SelectSome<TEntity> : SelectAllAndExpand<TEntity> | ||
{ | ||
public SelectSome(TEntity entity) : base(entity) | ||
{ | ||
|
||
} | ||
|
||
public SelectSome() | ||
{ | ||
|
||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,10 +109,12 @@ public void Bind_GeneratedExpression_ContainsExpandedObject() | |
|
||
// Assert | ||
IEnumerator enumerator = queryable.GetEnumerator(); | ||
IEnumerator _querableEnumerator = _queryable.GetEnumerator(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Assert.True(enumerator.MoveNext()); | ||
Assert.True(_querableEnumerator.MoveNext()); | ||
var partialCustomer = Assert.IsAssignableFrom<SelectExpandWrapper<QueryCustomer>>(enumerator.Current); | ||
Assert.False(enumerator.MoveNext()); | ||
Assert.Null(partialCustomer.Instance); | ||
Assert.Equal(_querableEnumerator.Current, partialCustomer.Instance); | ||
Assert.Equal("Microsoft.AspNet.OData.Test.Query.Expressions.QueryCustomer", partialCustomer.InstanceType); | ||
IEnumerable<SelectExpandWrapper<QueryOrder>> innerOrders = partialCustomer.Container | ||
.ToDictionary(PropertyMapper)["Orders"] as IEnumerable<SelectExpandWrapper<QueryOrder>>; | ||
|
@@ -464,7 +466,7 @@ public void ProjectAsWrapper_Element_ProjectedValueContainsInstance_IfSelectionI | |
} | ||
|
||
[Fact] | ||
public void ProjectAsWrapper_Element_ProjectedValueDoesNotContainInstance_IfSelectionIsPartial() | ||
public void ProjectAsWrapper_Element_ProjectedValueShouldContainInstance_IfSelectionIsPartial() | ||
{ | ||
// Arrange | ||
string select = "Id,Orders"; | ||
|
@@ -486,7 +488,7 @@ public void ProjectAsWrapper_Element_ProjectedValueDoesNotContainInstance_IfSele | |
Assert.Empty((projection as MemberInitExpression).Bindings.Where(p => p.Member.Name == "Instance")); | ||
Assert.NotEmpty((projection as MemberInitExpression).Bindings.Where(p => p.Member.Name == "InstanceType")); | ||
SelectExpandWrapper<QueryCustomer> customerWrapper = Expression.Lambda(projection).Compile().DynamicInvoke() as SelectExpandWrapper<QueryCustomer>; | ||
Assert.Null(customerWrapper.Instance); | ||
Assert.Equal(aCustomer, customerWrapper.Instance); | ||
Assert.Equal("Microsoft.AspNet.OData.Test.Query.Expressions.QueryCustomer", customerWrapper.InstanceType); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit: spelling "instance"