我想知道是否有可能有雙重嵌套linq同態。在EF代碼中嵌套Linq第一個
我有以下對象(我使用EF代碼第一)
public class Team
{
public int TeamId { get; set; }
public sting Name {get;set;}
public virtual ICollection<Person> People
}
public class Person
{
public int PersonId { get; set; }
[ForeignKey("Team")]
public int? TeamId { get; set; }
public Team Team { get; set; }
public virtual ICollection<Paper> Papers
}
public class Paper
{
public int PaperId { get; set; }
[ForeignKey("Person")]
public int? PersonId { get; set; }
public Person Person { get; set; }
public virtual ICollection<Paper> People
}
然後我用下面的LINQ statemate創建一個對象
(from t in db.Teams
select new TeamPapers
{
TeamName = t.Name
PaperTotal = t.People.Select(p=>p.Papers).Count()
}).ToList()
但PaperTotal只返回數ICollection < Paper>不是這些集合中的論文總數。我想知道是否有人知道如何做到這一點?
感謝那些工作,歡呼:) – 2012-02-22 16:39:44