如何获取C#中另一个对象内的对象计数?

时间:2016-02-23 19:16:28

标签: c#

应用程序类具有Applicant对象:

  public class Application
 { 
  public virtual ICollection<Applicant.Applicant> Applicants { get; set; }
 ...
 }

申请人类将Employee对象作为集合:

 public class Applicant
{
   public virtual ICollection<Employment> Employments { get; set; }
 } 

如何以这种方法获得就业人数:

  public void InsertApplication(Application application)

2 个答案:

答案 0 :(得分:4)

您可以使用application.SelectMany(a=>a.Applicants.SelectMany(x=>x.Employments)).Count()

答案 1 :(得分:0)

使用Count property可以检索Default Web Site Applicant次{...}

Employment

applicant.Employments.Count ApplicationEmployment计数是Applicant Employmentapplication.Applicants.Sum(applicant => applicant.Employments.Count); 点数的sum ...

heroku run rake db:schema:dump
heroku restart