0

LinqToSQL 我在从组中选择一列时遇到问题,下面是我的查询

var qry = (from i in INTERNETDATAs 
join c in COVERS on Convert.ToInt32(i.COVERTYPE) equals c.COV_TYPE
join b in BENEFITS on c.COVERID equals b.COVERID
join p in POLICies on i.REFERENCENO equals p.BACS_POLNO into grp
    where  i.DATELOADED >= new DateTime(2013,1,1)
    && i.DATELOADED < new DateTime(2014,1,1)
    && i.CAMPAIGNTYPE == "1"
    && c.COVERTYPEID == 17063789
orderby i.DOB   
select new
{
    i.ID,
    Campaign = i.CAMPAIGNTYPE,
    Title = i.TITLE,
    Dob = i.DOB,
    Accepted = i.ACCEPTED,
    BankLetter = i.BANKLETTER,
    //p.STATUS,
    //grp.STATUS,
    MonthlyPremium = c.MONTHLYPREMIUM,
    BenefitAmount = b.BENEFITAMOUNT,
    Description = b.BENEFITDESCRIPTION
}
).DefaultIfEmpty();         

 qry.Dump();

此查询给出了预期的结果,但我还需要表中的一STATUSPOLICies,当我删除评论//p.STATUS//grp.STATUS得到以下错误时

无法执行文本选择:

“System.Collections.Generic.IEnumerable”不包含“STATUS”的定义,并且找不到接受“System.Collections.Generic.IEnumerable”类型的第一个参数的扩展方法“STATUS”(按 F4 添加使用指令或程序集参考)

如果有人可以请帮助我解决这个问题,因为我已经尽我所能。

谢谢

4

1 回答 1

0

你是POLICIES按他们的BACS_POLNO领域加入的,把它想象成group bySQL。在最终选择器中,grp实际上是分组项目的集合,每个项目都可能具有不同的BACS_POLNO值。

如果要为每个 distinct 生成单独的项目BACS_POLNO,请执行常规连接:

join p in POLICies on i.REFERENCENO equals p.BACS_POLNO

或者,例如,您可以BACS_POLNO从分组集合中选择第一个:

var qry = (from i in INTERNETDATAs 
join c in COVERS on Convert.ToInt32(i.COVERTYPE) equals c.COV_TYPE
join b in BENEFITS on c.COVERID equals b.COVERID
join p in POLICies on i.REFERENCENO equals p.BACS_POLNO into grp
    where  i.DATELOADED >= new DateTime(2013,1,1)
    && i.DATELOADED < new DateTime(2014,1,1)
    && i.CAMPAIGNTYPE == "1"
    && c.COVERTYPEID == 17063789
orderby i.DOB   
select new
{
    i.ID,
    Campaign = i.CAMPAIGNTYPE,
    Title = i.TITLE,
    Dob = i.DOB,
    Accepted = i.ACCEPTED,
    BankLetter = i.BANKLETTER,
    grp.First().STATUS,
    MonthlyPremium = c.MONTHLYPREMIUM,
    BenefitAmount = b.BENEFITAMOUNT,
    Description = b.BENEFITDESCRIPTION
}
).DefaultIfEmpty();  
于 2013-08-29T15:53:49.893 回答