public List <TotalProvinceAdmissionsViewModel> GetTotalAdmittedKidsPerProvince(int Facility_Id) { int Province_Id = (from f in db.apl_Cyca_Facility join p in db.Provinces on f.Province_Id equals p.Province_Id where f.Facility_Id == Facility_Id select p.Province_Id).SingleOrDefault(); var models = db.CYCA_TotalFemalesAdmittedPerProvince(Province_Id).ToList(); var Malesmodels = db.CYCA_TotalMalesAdmittedPerProvince(Province_Id).ToList(); var viewModels = new List <TotalProvinceAdmissionsViewModel>(); int?totMale = 0; foreach (var m in Malesmodels) { totMale = m.Total; } foreach (var m in models) { //var totalDistrict = db.CYCA_TotalFemalesAdmittedPerDistrict(m.Province_Id).ToList(); viewModels.Add(new TotalProvinceAdmissionsViewModel { Province_Id = m.Province_Id, ProvinceName = m.ProvinceName, Gender = m.Gender, TotalFemales = m.Total, TotalMale = totMale, //Region_Id = Convert.ToInt32(totalDistrict.Where(a => a.Province_Id == m.Province_Id)), //RegionName = totalDistrict.Where(a => a.Province_Id == m.Province_Id).ToString() }); } return(viewModels); }