C
C#3y ago
Johnny

Linq Where JsonSerialization not working

Hey, is there a way to get the following running:
dbSet.Set<Table>().Where(x => JsonSerializer.Deserialize<Object>(x.Value).Number1 == localGivenNumber).ToList();
dbSet.Set<Table>().Where(x => JsonSerializer.Deserialize<Object>(x.Value).Number1 == localGivenNumber).ToList();
I am getting the error an expression tree cannot contain a call or invocation that uses optional arguments
3 Replies
Mayor McCheese
What does your table entity look like?
Becquerel
Becquerel3y ago
which part of that can take optional arguments? the json .Deserialize? in any case you just need to explicitly put in the default arguments oh -- or dbSet.Set() maybe the inability to handle optional arguments is just a failing of expression trees, nothing database related
Angius
Angius3y ago
The database can't do JSON deserialization, so of course this won't work. Either a) use a database that supports JSONB b) do the filtering on the client c) save this one particular value in its own column a) would be preferable, then c) b) is a last resort
Want results from more Discord servers?
Add your server