Skip to content

Commit

Permalink
update changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ElizabethOkerio committed Jul 25, 2023
1 parent 0d923e2 commit 7902c1e
Showing 1 changed file with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,19 +374,7 @@ internal Expression ProjectElement(QueryBinderContext context, Expression source
bool isSelectedAll = IsSelectAll(selectExpandClause);
if (isSelectedAll)
{
Expression sourceExpression = null;

if (QueryProvider != null &&
QueryProvider == HandleNullPropagationOptionHelper.EntityFrameworkQueryProviderNamespace ||
QueryProvider == HandleNullPropagationOptionHelper.ObjectContextQueryProviderNamespaceEF5 ||
QueryProvider == HandleNullPropagationOptionHelper.ObjectContextQueryProviderNamespaceEFCore2)
{
sourceExpression = UpdateMemberInitExpression(source, structuredType);
}
else
{
sourceExpression = source;
}
Expression sourceExpression = UpdateMemberInitExpression(source, structuredType);

// Initialize property 'Instance' on the wrapper class
wrapperProperty = wrapperType.GetProperty("Instance");
Expand Down Expand Up @@ -449,34 +437,46 @@ internal Expression ProjectElement(QueryBinderContext context, Expression source

// Generates the expression
// { Instance = new Customer() {Id = $it.Id}}
private static Expression UpdateMemberInitExpression(Expression source, IEdmStructuredType structuredType)
private Expression UpdateMemberInitExpression(Expression source, IEdmStructuredType structuredType)
{
Type elementType = source.Type;
IEnumerable<IEdmStructuralProperty> structuralProperties = structuredType.StructuralProperties();
List<string> structuralPropertyNames = new List<string>();
Expression sourceExpression = null;

foreach (IEdmStructuralProperty property in structuralProperties)
if (QueryProvider != null &&
QueryProvider == HandleNullPropagationOptionHelper.EntityFrameworkQueryProviderNamespace ||
QueryProvider == HandleNullPropagationOptionHelper.ObjectContextQueryProviderNamespaceEF5 ||
QueryProvider == HandleNullPropagationOptionHelper.ObjectContextQueryProviderNamespaceEFCore2)
{
structuralPropertyNames.Add(property.Name);
}
Type elementType = source.Type;
IEnumerable<IEdmStructuralProperty> structuralProperties = structuredType.StructuralProperties();
List<string> structuralPropertyNames = new List<string>();

foreach (IEdmStructuralProperty property in structuralProperties)
{
structuralPropertyNames.Add(property.Name);
}

PropertyInfo[] props = elementType.GetProperties();
List<MemberBinding> bindings = new List<MemberBinding>();
PropertyInfo[] props = elementType.GetProperties();
List<MemberBinding> bindings = new List<MemberBinding>();

foreach (PropertyInfo prop in props)
{
if (structuralPropertyNames.Contains(prop.Name))
foreach (PropertyInfo prop in props)
{
MemberExpression propertyExpression = Expression.Property(source, prop);
bindings.Add(Expression.Bind(prop, propertyExpression));
if (structuralPropertyNames.Contains(prop.Name))
{
MemberExpression propertyExpression = Expression.Property(source, prop);
bindings.Add(Expression.Bind(prop, propertyExpression));
}
}
}

NewExpression newExpression = Expression.New(source.Type);
NewExpression newExpression = Expression.New(source.Type);

MemberInitExpression memberInit = Expression.MemberInit(newExpression, bindings);
sourceExpression = Expression.MemberInit(newExpression, bindings);
}
else
{
sourceExpression = source;
}

return memberInit;
return sourceExpression;
}

private static bool ParseComputedDynamicProperties(QueryBinderContext context, IList<DynamicPathSegment> dynamicPathSegments, bool isSelectedAll,
Expand Down

0 comments on commit 7902c1e

Please sign in to comment.