OData.QueryBuilder
OData.QueryBuilder copied to clipboard
Odata query where the property type of Date is in string?
I want to have below odata query.
$filter=(Program eq 'E6' or Program eq 'NON')
and PricingCountry eq 'UK'
and PricingCurrency eq 'GBP'
and CustomerType eq 'USR'
and LicenseAgreementType eq 'CRP'
and StartDate le '2022-04-01T00:00:00.000Z'
and (EndDate eq null or EndDate ge '2022-04-30T00:00:00.000Z')
and (
(PartNumber eq '9TX-00635' and ProgramOffering eq 'ACP' and OfferingLevel eq 'D' and PurchaseUnit eq '1Y' and PurchasePeriod eq 'AAS' and DealDuration eq 60)
or
(PartNumber eq '9TX-00635' and ProgramOffering eq 'ACP' and OfferingLevel eq 'A' and PurchaseUnit eq '1Y' and PurchasePeriod eq 'AAS' and DealDuration eq 60)
)
I have written below code, everything is working except start date and end date as those are in String in Odata and i don't have control.
- If i keep in string then >= and <= is not possible and language won't allow.
- If i try to parse to DateTime or DateTimeOffset, package is giving error like its not able to parse.
var start = DateTimeOffset.ParseExact("2022-04-01T00:00:00.000Z", "yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture);
var end = DateTimeOffset.Parse("2022-04-30T00:00:00.000Z");
uri = uri.Filter((x, f, o) =>
(x.Program == "E6" || x.Program == "NON")
&& x.PricingCountry == "US"
&& x.PricingCurrency == "USD"
&& x.CustomerType == "USR"
&& x.LicenseAgreementType == "CRP"
&& x.CustomerType == "USR"
&& x.LicenseAgreementType == "CRP"
&& x.StartDate <= start
&& (x.EndDate == null || x.EndDate >= end)
&& (
(x.PartNumber == "021-05331" && (x.ProgramOffering == "CUS" || x.ProgramOffering == "NON") && (x.OfferingLevel == "A" || x.OfferingLevel == "NON") && x.PurchaseUnit == "1Y" && x.PurchasePeriod == "AAS" && x.DealDuration == 12)
|| (x.PartNumber == "021-05331" && (x.ProgramOffering == "CUS" || x.ProgramOffering == "NON") && (x.OfferingLevel == "B" || x.OfferingLevel == "NON") && x.PurchaseUnit == "1Y" && x.PurchasePeriod == "AAS" && x.DealDuration == 12)
), useParenthesis: true);
Hello! If understood correctly, then this should help https://github.com/ZEXSM/OData.QueryBuilder#-date