C#/LINQ & Infamous ORA-00933:SQL 命令未正确结束



我有以下 C#/LINQ 语句(使用 Visual Studio 2010)给了我上述错误:

var cityResults = TaxRates
    .Where(a => a.TaxType.Equals("CI"))
    .OrderBy(a => a.Description).ThenByDescending(a => a.CreateDate)
    .GroupBy(a => a.Description)
    .Select(grp => grp.FirstOrDefault());

我只是希望查询从 TaxRates 表中带回所有列,按描述分组并带回最新的 CREATEDATE 行。

运行甲骨文 9i。

对于它的价值,以下内容工作得很好,并且完全恢复了我想要的:

var cityResults = TaxRates
    .Where(x => x.TaxType.Equals("CI"))
    .OrderByDescending(x => x.CreateDate)
    .GroupBy(x => x.Description)
    .Select(x => x.First());

但是,这是因为我使用以下数据结构而不是针对数据库/表:

public static List<MyCities> TaxRates = new List<MyCities>
{
new MyCities {Description = "Boston",    TaxType = "CI", CreateDate = 120, TaxAmt = 5.7},
new MyCities {Description = "Houston",   TaxType = "CI", CreateDate = 116, TaxAmt = 5.7},
new MyCities {Description = "Boston",    TaxType = "CI", CreateDate = 121, TaxAmt = 5.6},
new MyCities {Description = "Las Vegas", TaxType = "CI", CreateDate = 114, TaxAmt = 5.7},
new MyCities {Description = "Boston",    TaxType = "CI", CreateDate = 115, TaxAmt = 5.9},
new MyCities {Description = "Phoenix",   TaxType = "CI", CreateDate = 118, TaxAmt = 5.7},
new MyCities {Description = "Colorado",  TaxType = "ST", CreateDate = 113, TaxAmt = 5.7},
new MyCities {Description = "Seattle",   TaxType = "CI", CreateDate = 112, TaxAmt = 5.7},
new MyCities {Description = "Orlando",   TaxType = "CI", CreateDate = 111, TaxAmt = 5.7},
new MyCities {Description = "Miami",     TaxType = "CI", CreateDate = 119, TaxAmt = 5.7},
new MyCities {Description = "Boston",    TaxType = "CO", CreateDate = 122, TaxAmt = 5.7},
new MyCities {Description = "Eugene",    TaxType = "CI", CreateDate = 121, TaxAmt = 5.7}
};
public class MyCities
{
    public string Description { get; set; }
    public string TaxType { get; set; }
    public int CreateDate { get; set; }
    public double TaxAmt { get; set; }
}

你能检查一下以下内容是否有效吗?

var cityResults = TaxRates .Where(a => a.TaxType.Equals("CI")) .OrderBy(a => a.Description).ThenByDescending(a => a.CreateDate) .GroupBy(a => a.Description) .Select(grp => grp.FirstOrDefault()); .ToList() .Dump();

相关内容

  • 没有找到相关文章

最新更新