我有一个包含TFS构建的测试程序集统计信息的表,如下所示:
AssemblyName Duration TestResults MsPerResult Branch
Ass1.dll 100 2 50 $/branch1
Ass2.dll 200 2 100 $/branch1/sub1
Ass3.dll 400 2 200 $/branch1/sub1/subsub1
...
此外,我有一个用于保存DataContext.ExecuteQuery<>的摘要类。结果
public class AssemblyStatistics
{
public string AssemblyName { get; set; }
public int TestResultCount { get; set; }
public long ValueInMs { get; set; }
}
如果我执行以下代码,我的查询总是花费相同的时间,即使我限制只查询子分支的结果:
context.ExecuteQuery<AssemblyStatistics>(
"SELECT TOP 10 AssemblyName, SUM(Duration) AS ValueInMs, SUM(TestResults) AS TestResultCount FROM AssembliesByDuration WHERE Branch LIKE {0} GROUP BY AssemblyName ORDER BY SUM(Duration) DESC", "$/branch1/sub1%").ToList();
但是使用以下(非websafe)格式,运行时按预期方式下降
context.ExecuteQuery<AssemblyStatistics>(
@"SELECT TOP 10 AssemblyName, SUM(Duration) AS ValueInMs, SUM(TestResults) AS TestResultCount FROM AssembliesByDuration WHERE Branch LIKE '"
+ "$/branch1/sub1%" + "' GROUP BY AssemblyName ORDER BY SUM(Duration) DESC").ToList();
我是否遗漏了某些内容,或者这只是Linq2SQL之后评估LIKE的问题?
答案 0 :(得分:0)
在第一个查询中,您似乎缺少{0}周围的单引号。