1

I am using MVC3, Razor, C# and EF4.1.

I am trying to implement some rule processing logic, and using the excellent FLEE rule processor at present. So rules such as :

a>1 and a<100

can be stored in the DB and processed at runtime. Great. However this assumes that I can preload "a" which in simple case I can. However sometimes it is necessary to get more detailed with my query and a dynamic type of LINQ would be great, ie

context.animals.first(r=>r.specie=="dog").Name

So one could then use this in the complete rule like:

(context.animals.first(r=>r.specie=="dog").Name) = "Rover"

It is "=" in FLEE and not "==" btw.

So can one implement dynamic LINQ queries and how?

The only other approach I can think of is substitution and use of switch ie:

{DogName}="Rover"

switch (argname)
{
case "DogName" :
  myValue = db.Animals.First(r=>r.specie=="Dog").Name
  break;
}
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
SamJolly
  • 6,347
  • 13
  • 59
  • 125
  • 1
    [Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library)](http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx) – GSerg Mar 06 '14 at 16:59
  • 1
    [Serialize.Linq - C# library to serialize LINQ expressions](https://github.com/esskar/Serialize.Linq) – GSerg Mar 06 '14 at 17:00
  • Ok, thanks folks, some excellent feedback, need to check these out. – SamJolly Mar 06 '14 at 17:09
  • 1
    There are a number of ways to do this. Dynamic Linq is one. Albahari's Predicate Builder is another. – Robert Harvey Mar 06 '14 at 17:09

0 Answers0