ZEXSM / OData.QueryBuilder

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

Add ToDictionary() and other things #19

Closed alexandresanlim closed 4 years ago

alexandresanlim commented 4 years ago

Add support ToDictionary():

In some cases it is necessary to send a dictionary to url.

eg:

var odataBuilder = new ODataQueryBuilder<Core.Data.DataModels.Booking>(ODataParameter.FakeUri)
                    .For<Core.Data.DataModels.Booking>(x => x)
                    .ByList()
                    .Top(top)
                    .Skip(skip)
                    .Filter(x => x.DataItem.Description.Title == "Test")
                    .OrderBy(x => x.CreatedAt);

var dic = odataBuilder.ToDicionary();

The result is: image

Send url with dicionary:

return await ServiceClient.InvokeApiAsync<List<Core.Data.DataModels.Booking>>("Booking/GetAllByDataStoreId", HttpMethod.Get, **dic**);

This modification does not change the ToUrl() :)

Add support Contains() text:

eg:

var uri = _odataQueryBuilder
                .For<ODataTypeEntity>(s => s.ODataType)
                .ByList()
                .Filter(s => s.ODataKind.ODataCode.Code.Contains("0") || s.ODataKindNew.ODataCode.Code.Contains("55"))
                .ToUri();

Url result: http://mock/odata/ODataType?$filter=substringof('0',toupper(ODataKind/ODataCode/Code)) or substringof('55',toupper(ODataKindNew/ODataCode/Code))

Add support enum ToString() compare:

eg:

 var uri = _odataQueryBuilder
            .For<ODataTypeEntity>(s => s.ODataType)
            .ByList()
            .Filter(s => **s.Color.ToString() == Color.Blue.ToString()**)
            .Skip(1)
            .Top(10)
            .ToUri();

Url result: http://mock/odata/ODataType?$filter=Color eq 'Blue'&$skip=1&$top=10

ZEXSM commented 4 years ago

Hi, I looked at the changes you want to make. In general, I support, but I want to make changes, taking into account how I see the use of current changes and the use of the library in the future

I wanted to publish a new branch and do PR in https://github.com/alexandresanlim/OData.QueryBuilder but I did not have enough rights :)

alexandresanlim commented 4 years ago

Nice! I invited you as a contributor, I think that solves the issue of access.

ZEXSM commented 4 years ago

I created a PR. If it meets all your requirements, then I propose to merge :)

https://github.com/alexandresanlim/OData.QueryBuilder/pull/1

alexandresanlim commented 4 years ago

Merge confirmed.