Skip to content
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

Querying Vogen value types throws exception #3450

Closed
rena0157 opened this issue Sep 26, 2024 · 4 comments
Closed

Querying Vogen value types throws exception #3450

rena0157 opened this issue Sep 26, 2024 · 4 comments

Comments

@rena0157
Copy link

When using the new value type integration in Marten an exception is thrown when trying to query the value.

Reproduction can be seen here

@nkosi23
Copy link

nkosi23 commented Sep 26, 2024

@rena0157 I think you need to use a where clause, i'm not sure the FirstOrDefault method is directly supported. Please try a where clause containing your predicate followed by FirstOrDefault:

https://martendb.io/documents/identity.html#snippet-sample_insert_the_load_by_strong_typed_identifier

A new LoadAsync overload was created by Jeremy to unwrap the id when building a query against the primary key. Similar work needs to be done for all linq overloads to take care of the translation of the linq expression tree for arbitrary queries, and there are plenty of method overloads to handle. This work isn't fun, and if I remember correctly not all cases are covered yet. However from my experience, PR's are welcome.

As an aside, I started working on something similar to query against Fsharp Discriminated unions here, but since I use F#, i decided to use unit of measures through the UMX library instead since they are compile-time abstractions resolving to the raw base type at runtime, much less hassle. I left the github issue open in case I find a compelling business case to further implement DU support.

@jeremydmiller
Copy link
Member

@nkosi23 Marten supports using the logical Where() clause in any kind of First/Single/OrDefault operator.

@jeremydmiller
Copy link
Member

The existing value type support was assuming that the value types would be struct. The record usage is breaking it for now. I can work around that I think

@jeremydmiller
Copy link
Member

Okay, so this was a couple different things:

  1. Marten was assuming that all the value types were going to be struct, so I had to make it work around that a little bit
  2. The LINQ support had to be explicitly taught how to do ValueType == SimpleType comparisons in the SQL generation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants