1

我有一个包含 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();

但是使用以下(非网络安全)格式,运行时按预期下降

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 的问题?

4

1 回答 1

0

在第一个查询中,您似乎缺少 {0} 周围的单引号。

于 2012-07-31T14:19:18.850 回答