nhibernate-core icon indicating copy to clipboard operation
nhibernate-core copied to clipboard

Add ToDictionaryAsync and ToHashSetAsync Linq extension methods

Open dennis-gr opened this issue 1 year ago • 4 comments

Convenience methods to avoid the slightly awkward syntax when doing it manually after calling ToListAsync.

Async-Generator fails to generate tests for ToDictionaryAsync, not sure why it doesn't get recognized.

dennis-gr avatar Mar 19 '24 17:03 dennis-gr

What is awkward? (await query.ToListAsync()).ToHashSet()? Or hashSet.UnionWith(await query.ToListAsync())?

I do not see the need.

fredericDelaporte avatar Apr 28 '24 16:04 fredericDelaporte

What is the awkward? (await query.ToListAsync()).ToHashSet()? Or hashSet.UnionWith(await query.ToListAsync())?

Both: the chained method call with the need to add parantheses around the async call, creating the HashSet yourself also isn't great IMHO.

It's a small usability improvement, I don't see the harm in adding these.

dennis-gr avatar Apr 30 '24 12:04 dennis-gr

I see some harm:

  • It may lure users into thinking the thing is optimized in order to directly load the result into a hashset/dictionary instead of going through an intermediate list.
  • That is still some additional code to maintain, just for sparing a couple of parenthesis to callers.

Other maintainers may see it otherwise, so, It leave it open.

fredericDelaporte avatar Apr 30 '24 20:04 fredericDelaporte

I see some harm:

* It may lure users into thinking the thing is optimized in order to directly load the result into a hashset/dictionary instead of going through an intermediate list.

Optimizing this would be possible as soon as https://github.com/nhibernate/nhibernate-core/pull/2274 is done. I'll add a remark that calling these methods still creates an intermediate list.

* That is still some additional code to maintain, just for sparing a couple of parenthesis to callers.

Like I said, ATM it's a small usability improvement that I think is worth it, with the option to provide a slightly optimized version in the future. EF Core has these methods and it would be nice if NH did too.

dennis-gr avatar May 01 '24 13:05 dennis-gr