Skip to content
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

Fix ArgumentException regression in ProjectPlanCompiler #2624

Merged
merged 2 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Microsoft.OData.Client/ProjectionPlanCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,8 @@ private Expression GetDeepestEntry(Expression[] path)
result = CallMaterializer(
nameof(ODataEntityMaterializerInvoker.ProjectionGetEntry),
result ?? this.pathBuilder.ParameterEntryInScope,
Expression.Constant(((MemberExpression)path[pathIndex]).Member.Name, typeof(string)));
Expression.Constant(((MemberExpression)path[pathIndex]).Member.Name, typeof(string)),
Expression.Constant(this.materializerContext));
pathIndex++;
}
while (pathIndex < path.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,8 @@ public async Task Linq_ProjectPropertiesFromEntityWithConditionalNullCheckOnExpa
.Select(c => new Computer
{
ComputerId = c.ComputerId,
// this contrived expression is to get the plan compiler to perform
// a null check against an expanded entity
ComputerDetail = c.ComputerDetail == null ? null : c.ComputerDetail,
}) as DataServiceQuery<Computer>;

Expand All @@ -807,6 +809,38 @@ public async Task Linq_ProjectPropertiesFromEntityWithConditionalNullCheckOnExpa
Assert.Equal(-10, computer.ComputerDetail.ComputerDetailId);
}

[Fact]
public async Task Linq_ProjectPropertiesFromNestedExpandedEntityToADifferentTargetTypeFromTheSource()
{
var context = this.CreateWrappedContext<DefaultContainer>().Context;
var query = context.ComputerDetail.Where(c => c.ComputerDetailId == -10)
.Select(c => new Computer
{
ComputerId = c.Computer.ComputerId,
}) as DataServiceQuery<Computer>;

var result = await query.ExecuteAsync();

var computer = result.First();
Assert.Equal(-10, computer.ComputerId);
}

[Fact]
public async Task Linq_ProjectPropertiesFromNestedComplexTypeToADifferentTargetTypeFromTheSource()
{
var context = this.CreateWrappedContext<DefaultContainer>().Context;
var query = context.Customer.Where(c => c.CustomerId == -10)
.Select(c => new ContactDetails
{
HomePhone = c.PrimaryContactInfo.HomePhone
}) as DataServiceQuery<ContactDetails>;

var result = await query.ExecuteAsync();

var contactDetails = result.First();
Assert.Equal("jqjklhnnkyhujailcedbguyectpuamgbghreatqvobbtj", contactDetails.HomePhone.Extension);
}

/// <summary>
/// LINQ query Project Name Stream Property
/// </summary>
Expand Down