Skip to content

Commit

Permalink
Merge pull request #31756 from dotnet-maestro-bot/merge/release/8.0-t…
Browse files Browse the repository at this point in the history
…o-main

[automated] Merge branch 'release/8.0' => 'main'
  • Loading branch information
msftbot[bot] authored Sep 15, 2023
2 parents 302c438 + 434a75a commit 120daf1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/EFCore/EF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal static MethodInfo MakePropertyMethod(Type type)
public static bool IsDesignTime { get; set; }

/// <summary>
/// References a given property or navigation on an entity instance. This is useful for shadow state properties, for
/// References a given property or navigation on an entity or complex type instance. This is useful for shadow state properties, for
/// which no CLR property exists. Currently this method can only be used in LINQ queries and can not be used to
/// access the value assigned to a property in other scenarios.
/// </summary>
Expand All @@ -54,11 +54,11 @@ internal static MethodInfo MakePropertyMethod(Type type)
/// </para>
/// </remarks>
/// <typeparam name="TProperty">The type of the property being referenced.</typeparam>
/// <param name="entity">The entity to access the property on.</param>
/// <param name="instance">The entity or complex type to access the property on.</param>
/// <param name="propertyName">The name of the property.</param>
/// <returns>The value assigned to the property.</returns>
public static TProperty Property<TProperty>(
object entity,
object instance,
[NotParameterized] string propertyName)
=> throw new InvalidOperationException(CoreStrings.PropertyMethodInvoked);

Expand Down
7 changes: 7 additions & 0 deletions src/EFCore/Infrastructure/ExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,13 @@ private static Expression CreateEFPropertyExpression(
propertyType = propertyType.MakeNullable();
}

// EF.Property expects an object as its first argument. If the target is a struct (complex type), we need an explicit up-cast to
// object.
if (target.Type.IsValueType)
{
target = Expression.Convert(target, typeof(object));
}

return Expression.Call(
EF.MakePropertyMethod(propertyType),
target,
Expand Down

0 comments on commit 120daf1

Please sign in to comment.