Skip to content

Allow passing complex type instances to ExecuteUpdate #32058

@xamir82

Description

@xamir82

Imagine this model:

public class User
{
    public int Id { get; set; }
    public required FullName FullName { get; set; }
}

[Owned]
public class FullName
{
    public required FirstName { get; set; }
    public required LastName { get; set; }
}

Inserting a User with by assigning a FullName object to the FullName property works:

db.Add(new User
{
    FullName = someFullNameObj,
});
db.SaveChanges();

But doing the same with ExecuteUpdate doesn't work:

db.Users.Where(u => u.Id == userId)
    .ExecuteUpdate(b => b
        .SetProperty(u => u.FullName, someFullNameObj)
    );

It throws an exception along these lines:

The LINQ expression ... could not be translated. The following lambda argument to 'SetProperty' does not represent a valid property to be set: 'u => u.FullName'.

This is an unexpected asymmetry between how insert and update work, I think most people would intuitively expect the ExecuteUpdate example to work just fine, it's a bit surprising, a weird limitation.

Let me know if there's an existing issue for this.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions