0

I have a price range query I'm trying to write for my C# code and depending on the currency type of the product I need to query the correct field

var minPrice = builder.Gte(s => s.Price.CurrencyCode == "USD" ? s.Price.Usd : s.Price.Foreign, filter.MinPrice);
var maxPrice = builder.Lte(s => s.Price.CurrencyCode == "USD" ? s.Price.Usd : s.Price.Foreign, filter.MaxPrice);

but when I run the code to test this I get the following error:

Unable to determine the serialization information for s => IIF((s.Price.CurrencyCode == ""USD""), s.Price.Usd, s.Price.Foreign).

if I take the ternary out and just look for the US price it works perfectly, but I need to be able to have it look for non US prices as well, am I doing something wrong?

Eman
  • 1,093
  • 2
  • 26
  • 49

1 Answers1

1

Not sure what's going on here (I think this kind of query is just not supported yet) but how about you rewrite the query like so:

    var minPrice = (builder.Where(s => s.Price.CurrencyCode == "USD") & builder.Gte(s => s.Price.Usd, filter.MinPrice))
                 | (builder.Where(s => s.Price.CurrencyCode != "USD") & builder.Gte(s => s.Price.Foreign, filter.MinPrice));
    var maxPrice = (builder.Where(s => s.Price.CurrencyCode == "USD") & builder.Lte(s => s.Price.Usd, filter.MaxPrice))
                 | (builder.Where(s => s.Price.CurrencyCode != "USD") & builder.Lte(s => s.Price.Foreign, filter.MaxPrice));
dnickless
  • 10,733
  • 1
  • 19
  • 34