Явное преобразование существует, когда я пытаюсь сгруппировать с помощью entity framework
привет,
я пытаюсь сгруппировать с помощью entity framework после фильтрации (предложение Where)
но эта ошибка появляется :
Cannot implicitly convert type 'System.Linq.IQueryable<dataObjects.CLSPeopleActivities>' to 'System.Linq.IQueryable<view_people_history>'. An explicit conversion exists (are you missing a cast?)
около :
.Select(grp => new CLSPeopleActivities { ID = grp.Key.PeopleID, Name = grp.Key.pepole_Name, Count = grp.Count(), Amount = grp.Sum(f => f.NetValue), Amount_Curr = grp.Sum(f => f.NetValue).ToString() + " " + currency, PercentOfTotal_Count = (grp.Count() / sTotalCount) * 100, PercentOfTotal_Amount = (grp.Sum(f => f.NetValue) / sTotalAmount) * 100, PercentOfTotal_Count_perc = ((grp.Count() / sTotalCount) * 100).ToString() + "%", PercentOfTotal_Amount_perc = ((grp.Sum(f => f.NetValue) / sTotalAmount) * 100).ToString() + "%", });
Что я уже пробовал:
var Query = DB1.view_people_history.Where(u=> u.PeopleID != 0); // Filter With Date if (checkDate.Checked) { Query = Query.Where(u => u.Opdate >= From && u.Opdate <= To); } // Branchs if (checkBranch.Checked && branchids.Count() > 0) { Query = Query.Where(u => branchids.Contains(u.BranchID)); } // Exclude the main account if (checkOperation.Checked) { Query = Query.Where(u => !PeopleMainAccounts.Contains(u.PeopleID)); } // Filter With Operation Type switch (OpTypeInput.EditValue) { case "purchases": Query = Query.Where(u => u.OpType == "PURCHASES"); break; case "sales": Query = Query.Where(u => u.OpType == "SALES"); break; case "rpurchases": Query = Query.Where(u => u.OpType == "RETURNED_PURCHASES"); break; case "rsales": Query = Query.Where(u => u.OpType == "RETURNED_SALES"); break; } // get Totals int sTotalCount = Query.Count(); decimal sTotalAmount = Query.Sum(s => s.NetValue.Value); string currency = CurrencyInfo.currencyShortcut(); // Group Query = Query.GroupBy(s => new { s.PeopleID, s.pepole_Name }) .Select(grp => new CLSPeopleActivities { ID = grp.Key.PeopleID, Name = grp.Key.pepole_Name, Count = grp.Count(), Amount = grp.Sum(f => f.NetValue), Amount_Curr = grp.Sum(f => f.NetValue).ToString() + " " + currency, PercentOfTotal_Count = (grp.Count() / sTotalCount) * 100, PercentOfTotal_Amount = (grp.Sum(f => f.NetValue) / sTotalAmount) * 100, PercentOfTotal_Count_perc = ((grp.Count() / sTotalCount) * 100).ToString() + "%", PercentOfTotal_Amount_perc = ((grp.Sum(f => f.NetValue) / sTotalAmount) * 100).ToString() + "%", });
Richard MacCutchan
Делайте то, что говорит вам сообщение, и используйте приведение к правильному типу.