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

Feature Request: Filter by property which is passed as a string variable #101

Closed prochnowc closed 1 year ago

prochnowc commented 1 year ago

Hi,

I have a use case where the user can enter the name of the property which should be used to filter the result set. Currently this is not possible because

string propertyName = "myProperty";
builder.Filter(e => propertyName == "test")

is being rendered as

propertyName eq 'test'

instead of the wanted

myProperty eq 'test'

Do you think you can add such feature ? Eg. by passing a special static function like so:

Filter(e => ODataProperty.ByName(propertyName) == "value")

Thanks in advance!

ZEXSM commented 1 year ago

Hi!

Please attach a complete usage example, starting with creating an ODataQueryBuilder instance.

Do I understand correctly that there is a need for a dynamic property name?

prochnowc commented 1 year ago

Do I understand correctly that there is a need for a dynamic property name?

yes

A complete example would be:

string propertyName = "ODataKind.ODataCode.IdCode";
new ODataQueryBuilder()
  .For<ODataTypeEntity>()
  .ByList()
  .Filter((s,f,_) => f.Property<int>(propertyName) >= 3)
  .ToUri();
ZEXSM commented 1 year ago

Do I understand correctly that there is a need for a dynamic property name?

yes

A complete example would be:

string propertyName = "ODataKind.ODataCode.IdCode";
new ODataQueryBuilder()
  .For<ODataTypeEntity>()
  .ByList()
  .Filter((s,f,_) => f.Property<int>(propertyName) >= 3)
  .ToUri();

Possibly related https://github.com/ZEXSM/OData.QueryBuilder/issues/99

prochnowc commented 1 year ago

What do you think about the PR @ZEXSM ? It would be great to have this feature merged.