Drop generic type constraint Query<T> to be T : class, and allow value types
See original GitHub issueAs of now https://github.com/elastic/elasticsearch-net/blob/master/src/Nest/QueryDsl/Query.cs is next
public static class Query<T> where T : class
Could you drop class
? I.e.:
public static class Query<T>
So I could write for stuct
s (i.e. value types)? Any reasons it is impossible?
Use case:
During usage of ElasticSearch as NoSQL storage for audit we do client side aggregation as elastic does not support summaries (sum,count) during usage of top_hits
aggregation.
Given different tactics, one of these like take first of all and take last for that day, leads to store millions entities in memory so it could be good to have these to be struct
s.
Another issues that trying to build LINQ provider for our case is impossible as LINQ provider methods has no class
constraint.
If class
consideration was for inheritance and proxy generation in future, do not do it.
Follow VITA ORM or other delegation pattern coding/code generation - use interfaces.
Why not build LINQ to low level client? I like typing and query validation done by NEST, otherwise why I use NEST at all for our usage case.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:14 (4 by maintainers)
Top GitHub Comments
Discussed and will consider making the change to drop the “where T : class” for user-defined document types.
The main reason why
T
is constrained toclass
is for all the inference we do based on types and down the line in expressions inside e.gField()
. It also signals that you can’t doSearch<string>
since_source
is always an object.C# needs a
struct
constraint badly 😦I’m not opposed to dropping the constraint but would like to explore the ramifications in terms of API misuse.
I agree with @KodrAus that
struct
on its own won’t have that much effect on GC (and his points onIQueryable
) but NEST should not be in the way of others attempting this.