views:

311

answers:

2

Can anybody explain me how to use (1) iQueryable (2) Expression Tree in c# by providing very basic example ? ( ofcourse both are not correlated,instead of making two separate questions,i wish to clear my doubt in a single question).

Advanced Thanks.

A: 

I generally don't like just linking stuff, but this is a more complicated topic. I suggest watching this video:

http://channel9.msdn.com/shows/Going+Deep/Erik-Meijer-and-Bart-De-Smet-LINQ-to-Anything/

Erik does a great job of explaining this, and gives a neat Linq to Simpsons example.

BFree
+2  A: 

Expression trees are very simple to make:

Expression<Func<int,int,int>> addExp = (a,b) => a + b;

or

var paramA = Expression.Parameter(typeof(int), "a");
var paramB = Expression.Parameter(typeof(int), "b");
Expression<Func<int,int,int>> addExp = Expression.Lambda<Func<int,int,int>>(
    Expression.Add(paramA, paramB),
    paramA,
    paramB);

Building an IQueryable provider is fairly difficult. However, Matt Warren has a very indepth series that walks you through creating an IQueryable provider.

sixlettervariables