ZEXSM / OData.QueryBuilder

OData.QueryBuilder - library for creating complex OData queries (OData version 4.01) based on data models with linq syntax.
MIT License
71 stars 31 forks source link

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

Open Prince269090 opened 1 year ago

Prince269090 commented 1 year ago

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.

           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 commented 11 months ago

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