Skip to content

How to map SetPropertyCalls<T>? #185

Closed

Description

@gordon-matt

I am trying to do something like this:

int affectedRows = realRepository.Update(
    p => p.ProductModelId == 5,
    s => s.SetProperty(p => p.Name, newName));

Where that method is defined on a generic repository as follows:

public virtual int Update(
    Expression<Func<TModel, bool>> predicate,
	Expression<Func<SetPropertyCalls<TModel>, SetPropertyCalls<TModel>>> setPropertyCalls,
	ContextOptions options = null)
{
    var mappedPredicate = entityModelMapper.MapPredicate(predicate);
    var mappedSetPropertyCalls = entityModelMapper.MapSetPropertyCalls(setPropertyCalls);
    using var context = GetContext(options);
    return context.Set<TEntity>().Where(mappedPredicate).ExecuteUpdate(mappedSetPropertyCalls);
}

And entityModelMapper.MapSetPropertyCalls looks like this:

 public Expression<Func<SetPropertyCalls<TEntity>, SetPropertyCalls<TEntity>>> MapSetPropertyCalls(
     Expression<Func<SetPropertyCalls<TModel>, SetPropertyCalls<TModel>>> setPropertyCalls) =>
     mapper.MapExpression<Expression<Func<SetPropertyCalls<TEntity>, SetPropertyCalls<TEntity>>>>(setPropertyCalls);

This is obviously not working. The unit test throws this error:

Message: 
System.InvalidOperationException : No generic method 'SetProperty' on type 'Microsoft.EntityFrameworkCore.Query.SetPropertyCalls`1[Extenso.TestLib.Data.Entities.ProductModel]' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. 

  Stack Trace: 
Expression.FindMethod(Type type, String methodName, Type[] typeArgs, Expression[] args, BindingFlags flags)
Expression.Call(Expression instance, String methodName, Type[] typeArguments, Expression[] arguments)
<>c__DisplayClass39_0.<VisitMethodCall>g__GetInstanceExpression|2(Expression instance)
XpressionMapperVisitor.VisitMethodCall(MethodCallExpression node)
MapperExtensions.<MapExpression>g__MapBody|8_1[TDestDelegate](Dictionary`2 typeMappings, XpressionMapperVisitor visitor, <>c__DisplayClass8_0`1&)
MapperExtensions.<MapExpression>g__CreateVisitor|8_0[TDestDelegate](Dictionary`2 typeMappings, <>c__DisplayClass8_0`1&)
MapperExtensions.MapExpression[TDestDelegate](IConfigurationProvider configurationProvider, LambdaExpression expression, Type typeSourceFunc, Type typeDestFunc, Func`3 getVisitor, Func`2 shouldConvertMappedBodyToDestType)
MapperExtensions.MapExpression[TDestDelegate](IMapper mapper, LambdaExpression expression, Func`3 getVisitor, Func`2 shouldConvertMappedBodyToDestType)
MapperExtensions.MapExpression[TDestDelegate](IMapper mapper, LambdaExpression expression)
AutoMapperEntityModelMapper`2.MapSetPropertyCalls(Expression`1 setPropertyCalls) line 42
MappedEntityFrameworkRepository`2.Update(Expression`1 predicate, Expression`1 setPropertyCalls, ContextOptions options) line 552
AutoMapperEntityFrameworkRepositoryTests.Update_WithPredicateAndSetPropertyCalls() line 806
RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Activity

  1. added a commit that references this issue on Jul 13, 2025
  2. BlaiseD commented on Jul 13, 2025

    @BlaiseD
    Member

    Yep - that's a bug. You can try the MyGet build.

  3. gordon-matt commented on Jul 14, 2025

    @gordon-matt
    Author

    Yeah my unit tests are passing now. Any idea when you'll put this on the official NuGet feed?

  4. added a commit that references this issue on Jul 14, 2025
  5. BlaiseD commented on Jul 14, 2025

    @BlaiseD
    Member

    Yeah my unit tests are passing now. Any idea when you'll put this on the official NuGet feed?

    v9.0.1.

  6. gordon-matt commented on Jul 15, 2025

    @gordon-matt
    Author

    @BlaiseD I had some issues with filtered includes as well. Are you aware of this or should I open a new case for you to have a look at that?

  7. BlaiseD commented on Jul 15, 2025

    @BlaiseD
    Member

    No - not aware of filtered include issues. Best to add a new issue. A test reproducing the failing case will help anyone trying to resolve the issue. Here's an example from the Set property problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions