Open Wolfware2023 opened 1 year ago
Hey @Wolfware2023,
Please post runnable code replicating the exception.
While removing more company code, I noticed my mistake. MyObject was not a class, but of type record. That caused the exception. Now with it being a class, it works as expected. Thanks.
I have encountered the same issue. This happens with records or any type that override Equals. The exception happens because of this line: https://github.com/radzenhq/radzen-blazor/blob/cae80096e12802de1498857272f0bce5f3b3bd77/Radzen.Blazor/RadzenDataGrid.razor.cs#L2380C28-L2380C28 If you use a record (which compares by value), or implement a custom comparison logic, it is more than likely the comparison will fail since you are, after all, editing the columns. This does not happen on vanilla classes since the default comparator only compares references, not actual values. Imho this is a bug since I don't think this should happen, especially if you specify a custom KeyProperty.
Arghh.. just got bitten by this again since I'm using records for my ViewModels.. which I thought was good practice.. and doesn't seem like there's any other way to resolve this... :-(
Records are immutable types, changing the data requires creating of new objects.
C# records are not necessarily immutable. One could very well want to use the automatic equality comparison of records without requiring it to be immutable, and this is in fact a supported use case. And in any case, as I noted, regular classes which override Equals will also trigger this exception. In my opinion it does not make sense to rely on the instance-provided equality comparison in an 'edit' context since the object is most likely going to be mutated. If it compares by anything other than reference, you are going to get bitten by this.
The editContext dictionary should override the provided equality comparison and use a reference comparer instead. If that is not feasible, one should be able to provide a custom equality comparer to override the default, or at the very least specify which property should be used for equality comparison.
I ran into this issue too. Supporting mutable records would be really nice.
Ok sure. I'll reopen this issue then.
Hey @Wolfware2023, We accept pull requests also!
I am replicating the example DataGrid inline edit Displaying and switching to edit mode works fine. But when I change a text value and save it, I get an error during the call of
await objectGrid.UpdateRow(currentObject);
The error message is
To Reproduce Steps to reproduce the behavior:
Expected behavior It should work without error like in the example, calling the method defined for RowUpdate next.
Additional context