1

I'm using entity framework and I will recieve a dictionary of objects in the controller and that will help me to create a predicate on the repository.

I don't know how to create a dynamic predicate using the Dictionary Keys and Values. All Keys will be named as entity properties, that means that on the followed example, the entity person have a property called Surname, and I want all Items with the surname Elliot.

Dictionary<string,Obect>()

With the followed data Key/Value:

 - "Surname","Elliot"
user1520494
  • 1,134
  • 2
  • 11
  • 27
  • It sounds like you'll need to use reflection for this, that will be expensive. – Dai Nov 13 '14 at 07:38
  • Hi Dai ty, an example will be very usefull! I was trying to do it by reflection.. but the problem is that when I have the object I don't know how to create the lambda expresion -.-' – user1520494 Nov 13 '14 at 07:42
  • Does this help? http://stackoverflow.com/questions/14835090/dynamically-generate-predicate-at-runtime – adiga Nov 13 '14 at 07:44

1 Answers1

1

Once you master the art of building dynamic queries life becomes easy.

Method 1 :

You can use dynamic linq expressions.

You have to use Dynamic Linq from NuGet

Once you have Dynamic Linq, you can write strings as queries and pass it as string in your where clause

For more information visit

Method 2:

Follow this link

Rama Kathare
  • 920
  • 9
  • 29