question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for HashSet<T> properties?

See original GitHub issue

Lasciate Ogni Speranza, Voi Ch’entrate

This thread is a wild ride. You’ve been warned.


For my use case, a HashSet<long> property is preferable to List<long>, but it seems even though most other collections get mapped to array columns in Postgres without issue, HashSet<T> does not.

Is there any chance that it’ll be supported in the future? And, for now, is there any way I can tell Npg to treat it as a List<T>?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:24 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
rojicommented, Oct 3, 2021

@Atulin the timestamp errors are due to a big change that was introduced in 6.0.0-rc.1. In a nutshell, the provider now strictly maps UTC DateTimes to timestamp with time zone and Local/Unspecified DateTimes to timestamp without time zone; it also no longer allows you to mix these two types (e.g. by comparing them).

See the release notes for more details. In any case, this shouldn’t be related to your HashSet work above

1reaction
Atulincommented, Oct 2, 2021

Aight, not as scary as I thought, it all boils down to

public class NpgHashsetConverter<T> : ValueConverter<HashSet<T>, List<T>>, INpgsqlArrayConverter
{
    public NpgHashsetConverter() : base(
        hs => new List<T>(hs), 
        ls => new HashSet<T>(ls)
        ) { }

    public ValueConverter ElementConverter => new ValueConverter<T, T>(x => x, x => x);
}

it would seem.

But now I’ve no clue how to even use this thing. I thought this is going to be fine

public class ChaptersRead
{
    // ...
    public HashSet<long> Chapters { get; init; }

    public class Configuration : IEntityTypeConfiguration<ChaptersRead>
    {
        public void Configure(EntityTypeBuilder<ChaptersRead> builder)
        {
            builder
                .Property(cr => cr.Chapters)
                .HasPostgresArrayConversion<long, HashSet<long>>(new NpgHashsetConverter<long>());
        }
    }
}

but it seems not, it wants me to use a long[] array somewhere there for some godforsaken reason image

Read more comments on GitHub >

github_iconTop Results From Across the Web

HashSet in Java
Java HashSet class implements the Set interface, backed by a hash table which is actually a HashMap instance. No guarantee is made as...
Read more >
HashSet (Java Platform SE 7 )
Constructs a new set containing the elements in the specified collection. The HashMap is created with default load factor (0.75) and an initial...
Read more >
HashSet in Java - Scaler Topics
Java HashSet Features · It allows storing only one null value. · The elements are stored using the hashing mechanism. · HashSet class...
Read more >
HashSet in Java
HashSet stores the elements by using a mechanism called hashing. · HashSet contains unique elements only. · HashSet allows null value. · HashSet...
Read more >
A Guide to HashSet in Java
HashSet is one of the fundamental data structures in the Java Collections API. Let's recall the most important aspects of this implementation:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found