npgsql / efcore.pg

Entity Framework Core provider for PostgreSQL
PostgreSQL License
1.56k stars 225 forks source link

Provide an optional value comparer for JsonDocument/JsonElement #1393

Open roji opened 4 years ago

roji commented 4 years ago

But require users to set it up explicitly, since this can be very heavy perf-wise.

Raised in https://stackoverflow.com/questions/62021228/entity-framework-not-detecting-jsonb-properties-changes-in-c-sharp

MarshalOfficial commented 2 years ago

Hi @roji, Will there be an update for this in the near future?

roji commented 2 years ago

@MarshalOfficial not at the moment, this is in the backlog and there are more important things happening for 7.0. Note that it's really easy to do this yourself in your application - simply set up the comparer yourself (EF docs) (that's one reason why I haven't prioritized it yet).

MarshalOfficial commented 2 years ago

@MarshalOfficial not at the moment, this is in the backlog and there are more important things happening for 7.0. Note that it's really easy to do this yourself in your application - simply set up the comparer yourself (EF docs) (that's one reason why I haven't prioritized it yet).

Yes, you are right. When I think about performance overhead, I come to the conclusion that handling this issue is not a difficult task.

var obj = await _dbContext.json_table.FirstOrDefaultAsync(a => a.id == id);
obj.child_data.some_property = new_value;
_dbContext.Entry(obj).Property(e => e.child_data).IsModified = true;
await _dbContext.SaveChangesAsync();
roji commented 2 years ago

Yes, manually telling EF when the property has changed is certainly more efficient than having it compare deep JSON documents each time SaveChanges is called.