示例#1
0
        /// <summary>
        /// Return the number of countries having reported per year for the area filter given
        /// </summary>
        /// <param name="areaFilter"></param>
        /// <returns></returns>
        public static IEnumerable <ReportingCountries> GetReportingCountries(AreaFilter areaFilter)
        {
            DataClassesFacilityDataContext db = getDataContext();

            ParameterExpression param = Expression.Parameter(typeof(FACILITYSEARCH_MAINACTIVITY), "s");
            Expression          exp   = LinqExpressionBuilder.GetLinqExpressionArea(areaFilter, param);

            // create lambda according to filters
            Expression <Func <FACILITYSEARCH_MAINACTIVITY, bool> > lambda = Expression.Lambda <Func <FACILITYSEARCH_MAINACTIVITY, bool> >(exp, param);

            IEnumerable <ReportingCountries> years = db.FACILITYSEARCH_MAINACTIVITies.Where(lambda)
                                                     .GroupBy(f => f.ReportingYear)
                                                     .Select(s => new  ReportingCountries(
                                                                 s.Key,
                                                                 s.Select(x => x.CountryCode).Distinct().Count()));

            return(years);
        }