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

Odata query where the property type of Date is in string? #111

Open
Prince269090 opened this issue Apr 6, 2023 · 1 comment
Open

Odata query where the property type of Date is in string? #111

Prince269090 opened this issue Apr 6, 2023 · 1 comment

Comments

@Prince269090
Copy link

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);
@ZEXSM
Copy link
Owner

ZEXSM commented Aug 17, 2023

Hello! If understood correctly, then this should help
https://github.com/ZEXSM/OData.QueryBuilder#-date

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

2 participants