Vogen icon indicating copy to clipboard operation
Vogen copied to clipboard

[Question] Vogen in "dynamic" EntityFramework Core situations

Open mkalinski93 opened this issue 1 year ago • 3 comments

Describe the feature

Hello,

I´m working on a project, which heavily uses Vogen, that needs to filter values submitted by the FrontEnd, on the BackEnd with IQueryable.

I would say that 95% of the cases are doing great and I´m enjoying the work with Vogen so far. Now I´ve encountered one specific type of problem that is drastically putting me into the corner. I need to filter values with a "Contains" or "IN" operation. For example, I have a List of Guid/string supplied from the frontEnd that needs to filter the property 'Id: UserId' (that´s my ValueObject here). I will receive the property name "id" and a collection of Guid/String values. The real problem starts here: Whenever I "dynamically" want to filter the database, I have limited choices:

  1. Use a custom library that parses strings into Expression - like Gridify, Dynamic.LINQ and so on
  2. Implement my own library - I´m not scared of
  3. Implement some sort of "EF.Property" butchery - not a fan of

But all three choices brought me back to a single point of failure - Type safety. If the QueryFilter object doesn´t explicitely contains the type of UserId, either as an object or as a generic collection, I´m done. I would need to explicitely specify the type, otherwise EfCore cannot work with it.

Whenever I try to provide some sort of "dynamic filter", the ValueConverter of EfCore will be in charge, converting the values back and forth (Primitive <-> ValueObject) and I cannot use primitive types from the request as it expects the real ValueObject with correct type. The result will always be empty. And it makes sense. Now, after a few days of pain, I finally want to reliefe myself and write down this question. Is there anybody here, that has found a solution to it?

mkalinski93 avatar Nov 08 '24 12:11 mkalinski93

Hi, thanks for starting this discussion. It sounds like a common enough scenario, so I'm sure we can get something working.

Would you be able to provide a minimal repro that I could compile and run to see what needs to be done.

SteveDunn avatar Nov 10 '24 12:11 SteveDunn

Hi!

While I am not the OP, I think I recreated a minimal repro that explains the problem. https://gist.github.com/ErgEnn/ae8bda788bdc9c4fb5807774510d5d35

ErgEnn avatar Mar 24 '25 21:03 ErgEnn

Thank you @ErgEnn - I'll try to get around to this soon.

SteveDunn avatar Mar 25 '25 22:03 SteveDunn