ef core plus: ArgumentNullException: Value cannot be null. Parameter name: property

entity-framework-core entity-framework-plus

Question

With ef core plus, I'm trying to update a set of rows on my model:

await _context.Set<Critique>()
            .Include(c => c.User)
            .Where(c => c.Closed && c.User.Id == user.Id)
            .UpdateAsync(c => new Critique() { User = deletedUser });

Here I get the following Exception:

ArgumentNullException: Value cannot be null. Parameter name: property Npgsql.EntityFrameworkCore.PostgreSQL.Utilities.Check.NotNull(T value, string parameterName) in Check.cs, line 21

TargetInvocationException: Exception has been thrown by the target of an invocation. System.RuntimeMethodHandle.InvokeMethod(object target, object[] arguments, Signature sig, bool constructor, bool wrapException

When I just load the data with ef core, it loads the 1 row I expect

var test = await _context.Set<Critique>()
            .Where(c => c.Closed && c.User.Id == user.Id)
            .ToArrayAsync();

The database model is nothing fancy but is too large to post here. I'm using [Required] extensively, and there are plenty of One-to-Many relations.

(Btw, user.Id is not null and available, and deletedUser is also available both in code and in the database.)

How should this error be interpreted? What am I doing wrong?

Thanks for your help!

Accepted Answer

Our library can update value but cannot update value using navigation property at this moment

This doesn't work

.UpdateAsync(c => new Critique() { User = deletedUser });

But this would have worked if you had the property

.UpdateAsync(c => new Critique() { UserID = deletedUserID });

Also, there is no point to add .Include(c => c.User) since you don't retrieve this information.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why