Linq query definition
I'm using the Windows Azure Toolkit product on codeplex. It looks perfect to meet my needs but there are very few examples out there. In particular there is a method to get data from Azure table开发者_如何学运维s:
public virtual T Get(Expression<Func<T, bool>> predicate)
{
return this.Query.Where(predicate).FirstOrDefault();
}
The problem is there are NO examples in the toolkit and I can't understand what the argument:
(Expression<Func<T, bool>> predicate)
should look like.
Is there anyone out there with a knowledge of Linq and C# that could give me some advice or suggestions that I could try.
Thanks in advance,
It's just a predicate, a method that accepts a parameter of type T
and returns a boolean - easiest way to use this is by passing a lambda expression - simple example:
public class Foo<T>
{
IQueryable<T> Query;
public virtual T Get(Expression<Func<T, bool>> predicate)
{
return this.Query.Where(predicate).FirstOrDefault();
}
}
...
Foo<int> foo = new Foo<int>();
int firstValueUnder100 = foo.Get(x => x <= 100);
Another example (return everything)
foo.Get(x => true);
brokenglass got there 1st, but another example would be:
foo.Get(x => x.OrderID == paramid);
where paramid was some arbitary parameter or variable etc
精彩评论