This issue is to track the work on this feature discussed on discord that I am currently implementing. The goal is to make it possible to query based on the case of an F# discriminated union property. For example given the following types:
type City = { Name: string; ZipCode: string }
type Country = { Name: string; Code: string; }
type Regions =
| Country of Country
| City of City
| Continent of Country list
type Survey = { Id: Guid; Topic: string; Target: Regions }
The goal is to add a Query API of the form .WhereDiscriminatedUnionHas<TDocument, TUnion, TCase>(Func<TDocument, TUnion> lambda, Func<TCase, bool>) like the below:
Query<Survey>().WhereDiscriminatedUnionHas<Survey, Regions, Country>(x => x.Target, x => x.Code == "US")
[ ] Build the feature by implementing specialized IQueryableMember / IMemberSource
[ ] Automatically add indexes for properties of type F# discriminated unions to select based on the case more efficiently
[ ] Add an API to allow users to define computed indexes for specific discriminated union cases (to enable querying efficiently on case-specific properties)
[ ] Nice to have: support arbitrary JSON serialization format instead of restricting users to persist DUs using a specific format (will need to think through how to pull that one off without introducing a dependency on a specific serialization library while avoiding reinventing the serialization world in a poor manner)
Todo
[ ] Add Linq tests to LinqTests/Acceptance/discriminated_unions_where_extensions.cs
[ ] Add index creation tests to MartenRegistryTests.cs
This issue is to track the work on this feature discussed on discord that I am currently implementing. The goal is to make it possible to query based on the case of an F# discriminated union property. For example given the following types:
Which are persisted to the following json:
The goal is to add a Query API of the form
.WhereDiscriminatedUnionHas<TDocument, TUnion, TCase>(Func<TDocument, TUnion> lambda, Func<TCase, bool>)
like the below:Items to deliver
IQueryableMember
/IMemberSource
.WhereDiscriminatedUnionHas<TDocument, TUnion, TCase>(Func<TDocument, TUnion> propertySelector, Func<TCase, bool> predicate)
.WhereDiscriminatedUnionIs<TDocument, TCase, TUnion>(Func<TDocument, TUnion> propertySelector)
Todo