Linq 查询定义
我正在 codeplex 上使用 Windows Azure Toolkit 产品。它看起来很能满足我的需求,但例子很少。特别是有一种从 Azure 表获取数据的方法:
public virtual T Get(Expression<Func<T, bool>> predicate)
{
return this.Query.Where(predicate).FirstOrDefault();
}
问题是工具包中没有示例,我无法理解参数:
(Expression<Func<T, bool>> predicate)
应该是什么样子。
有没有了解 Linq 和 C# 的人可以给我一些我可以尝试的建议或建议。
提前致谢,
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 tables:
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,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它只是一个谓词,一个接受
T
类型的参数并返回一个布尔值的方法 - 最简单的使用方法是传递 lambda 表达式 - 简单的示例: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:另一个例子(返回所有内容)
Another example (return everything)
brokenglass 第一个到达那里,但另一个例子是:
foo.Get(x => x.OrderID == paramid);
其中 paramid 是一些任意参数或变量等
brokenglass got there 1st, but another example would be:
foo.Get(x => x.OrderID == paramid);
where paramid was some arbitary parameter or variable etc