mardi 23 juin 2015

Lambda, how to sum and count?

namespace PJ.Domain.Entities
{
    [Table("test")]
    public class Test
    {
        [Key]
        public int id {get; set;}
        public child_1_id {get; set;}
        public child_2_id {get; set;}
        public string f_name{get; set;}
        public string l_name{get; set;}

        [ForeignKey("child_1_id")]        
        public virtual ICollection<Child1> child1 { get; set; }

        [ForeignKey("child_2_id")]        
        public virtual ICollection<Child2> child2 { get; set; }

    }
}

// Controller

IQueryable<Test> TestQuery = unitOfWork.TestRepository.getDbSet();

var items = (from i in TestQuery
                select new
                {
                    fName = i.f_name,
                    lName = i.l_name,
                    child1Cnt = //! child1 count(x.id)
                    child2Sum = //! child2 sum(x.age)

how to count and sum for child1 and child2?

Aucun commentaire:

Enregistrer un commentaire