-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
After updating to 8.0, mapping array column to a hashset no longer works #3038
Comments
@Atulin I Have the same issue but with IEnumerable collection type. |
Note: |
@Atulin and others, there have been some pretty far-reaching changes in how the provider handles array/collections, due to the work on primitive collections on the EF side. I'll definitely take a look at this when I get some spare time. |
Ah, so a somewhat-expected regression, then. In the meantime, could you maybe add a mention of it to the list of 8.0 breaking changes, or the docs about primitive collections? |
Everyone, sorry it took so long to answer this - and I don't have a great answer; EF 8.0's support for primitive collection currently doesn't support HashSet properties - this is tracked by dotnet/efcore#33115, see there for some explanations on why mapping HashSet isn't straightforward. The workaround is to switch to e.g. I'll go ahead and close this as this needs to be resolved on the EF side first and foremost; any additional work on the EFCore.PG side after that will be tracked separately. |
BTW if there are specific reasons why mapping HashSet to PG array is needed (over array/List), I'd be interested to hear them... I get that sometimes a PG array is used as if it were a set (e.g. for containment checks only) - and I agree it makes sense to support this - I'm just looking for any other specific reasons I might not be aware of. |
The specific reason in my case is probably the most obvious one: being able to map a set of unique values easily. Instead of having to do thing.Numbers.Add(7);
thing.Numbers = thing.Numbers.Distinct(); or some other variation thereof, where thing.Numbers.Add(7); and with that alone ensure, that |
My usecase is the same as Atulin's - specifically that I find myself in a situation where I wish to take advantage of |
Thanks @Atulin @QuantumToasted. The use-case is valid, just remember that the PG type you're mapping to (i.e. arrays) really do not correspond to the .NET type you want (HashSet). Specifically, reading database arrays into HashSet loses data (both ordering and duplicates). But for those scenarios where that's OK, I do agree we should look into supporting them. In the meantime, you can also continue using a HashSet property, but configure it as unmapped with EF, and have a mapped private property that reads/writes to the HashSet property. That should get you to a very similar place, which a bit of extra wrapping logic. |
I have an entity with the following property:
Before 8.0 I used this converter
and this model config
to make it work. After updating to a pre-release version of NpgSQL 8.0 I would get this exception:
Now, I updated the project wholesale to non-preview 8.0, so both EF Core and NpgSQL are at version 8.0.0. Apparently, said version removed
INpgSqlArrayConverter
interface, and changed how primitive collections are handled in the first place.Following the breaking changes note, I modified my model config to be just
however, an exception still occurs:
The text was updated successfully, but these errors were encountered: