如何在LINQ中自定义原因? [英] how to do customize where cause in LINQ?

查看:80
本文介绍了如何在LINQ中自定义原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 XElement doc = XElement.Load(@"SPDependencies.xml");


IEnumerable<XElement> sps = from s in doc.Elements("node")
where s.Attribute("type").Value == "StoredProcedure"
&& s.Attribute("Name").Value == "SPName(TotalTableCount)"
select s;


有没有办法可以实现这样的方式,我可以通过变量分配我的查询来自定义我的查询?像这样:


is there  a way where i can achieve some like this where I can customize my queries by assigning them through a variable? Like this:

string myCause = "s.Attribute("type").Value == "StoredProcedure"
                            && s.Attribute("Name").Value == "SPName(TotalTableCount)"";

IEnumerable<XElement> sps = from s in doc.Elements("node")
                            where myCause
                            select s;

推荐答案

我认为您的案例需要 编译查询 。当您的应用程序多次执行结构相似的查询时,您通常可以通过一次编译查询并使用不同的参数执行多次来提高性能。请参阅MSDN页面 http://msdn.microsoft.com/en-us/library/bb399335.aspx 有关详细信息和示例。

I think you need compiled queries for your case. When you have an application that executes structurally similar queries many times, you can often increase performance by compiling the query one time and executing it several times with different parameters. Please refer to MSDN page http://msdn.microsoft.com/en-us/library/bb399335.aspx for details and examples.


这篇关于如何在LINQ中自定义原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆