mardi 7 juillet 2020

Dynamic Sql filter Query in C#

I have a table in mySql and it's contains 10 columns.I am implementing Get Api to fetch the data based on filter in query prams.

For Example :-

Select Data From myTable where id=2 AND eId=6 or Select Data From myTable where id=2 AND rlNumber=6 AND version=8 etc.

I have following approaches:-

  1. Pass the where condition from Business Layer but in this case i am exposing DL info in BL.
  2. using reflection (i will generate the Where condition based on pass parameters). We shpuld avoid reflection.
  3. Create a Enum like FilterType and create a dictionary. key will be Enum and value will be where condition.

any better approach ?

Aucun commentaire:

Enregistrer un commentaire