Closed
Description
openedon Oct 16, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment