【发布时间】:2012-03-21 12:33:08
【问题描述】:
我正在为一组文件结果做一个小查询。
public class f_results
{
public String name { get; set; }
public DateTime cdate { get; set; }
public DateTime mdate { get; set; }
public DateTime adate { get; set; }
public Int64 size { get; set; }
}
我有一个屏幕,用户可以在上面选择他们想要的内容。目前我正在通过过滤系统:
foundfiles = new BindingList<f_results>(totalresults.Find(fname.Text,true));
if (fsize.Text.Trim() != "")
{
try
{
Int64 sz = Int64.Parse(fsize.Text);
List<f_results> y = (from p in foundfiles where p.size >= sz orderby p.size descending select p ).ToList();
foundfiles = new BindingList<f_results>(y);
}
catch
{ }
}
if (adate.Text.Trim() != "")
{
try
{
List<f_results> y;
DateTime test = DateTime.Parse(adate.Text);
if ((adateop.Text) == ">")
{
y = (from p in foundfiles where p.adate >= test select p).ToList();
}
else
y = (from p in foundfiles where p.adate <= test select p).ToList();
foundfiles = new BindingList<f_results>(y);
}
catch
{ }
}
if (mdate.Text.Trim() != "")
{
try
{
List<f_results> y;
DateTime test = DateTime.Parse(mdate.Text);
if ((mdateop.Text) == ">")
{
y = (from p in foundfiles where p.mdate >= test select p).ToList();
}
else
y = (from p in foundfiles where p.mdate <= test select p).ToList();
foundfiles = new BindingList<f_results>(y);
}
catch
{ }
}
if (cdate.Text.Trim() != "")
{
try
{
List<f_results> y;
DateTime test = DateTime.Parse(cdate.Text);
if ((cdateop.Text) == ">")
{
y = (from p in foundfiles where p.cdate >= test select p).ToList();
}
else
y = (from p in foundfiles where p.cdate <= test select p).ToList();
foundfiles = new BindingList<f_results>(y);
}
catch
{ }
}
最后,我得到了我想要的结果,但我希望处理大约 72 TB 的文件数据,所以我的列表中有很多文件和目录(totalresults 是一个类型的结果,其中包含文件 (f_results) 和目录 (results) 的列表。Find 然后向下迭代并返回与给定正则表达式匹配的大量 f_results 列表。
有没有办法让我的 LINQ 查询一次查询?鉴于并非所有选项都可能使用,例如他们可能只想要文件 > x,或者自.. 或.. 等之后不再使用。
我确实考虑过为测试制作标志,等等,因为它是最重要的测试部分。这是更好的方法,还是有更好的方法?还是说洗完没关系?
【问题讨论】:
-
要加速大型输入处理,您可以使用Parallel LINQ (PLINQ)?
-
也许,你有一个我的问题的示例答案(而我试图用棍子戳它,看看我是否可以用其他方式做到这一点?)-顺便说一句,顺序 linq 的示例显示 msdn.microsoft.com/en-us/library/dd460680.aspx 和它并没有真正涵盖这个问题的实际顺序 linq 查询。
-
我又读了一次问题,所以您希望能够根据指定为字符串的过滤器参数动态构建单个 LINQ 查询吗?或者你的主要目标是什么?