Answered by:
Operator '&&' cannot be applied to operands of type 'bool' and 'System.Collections.Generic.IEnumerable<bool>'_

Question
-
User2020942139 posted
project = db.Project.Where(c => c.ID == id && c.ProjectTasks.Select(a => a.isCompleted == false)). Include(c => c.ProjectTasks.Select(b => b.ProjectTaskProgresses)). Include(c => c.ProjectTasks.Select(a => a.ProjectTaskLeads)). SingleOrDefault();
Help! I want to select all completed tasks within a project. Here is my code.
Tuesday, September 1, 2015 6:36 AM
Answers
-
User281315223 posted
I would think it would make more sense to query the actual Task objects themselves if that would be applicable in your situation. This assumes that you actually have a separate table for your ProjectTasks and that you would actually need the tasks themselves :
var completedTasks = db.ProjectTasks.Where(p => p.ProjectID == id && c.IsCompleted);
If that wouldn't work, then you would likely want to apply your includes and then filter those results by only the tasks you are looking for :
var project = db.Project.Include("ProjectTasks.ProjectTaskProgresses,Projecttasks.ProjectTaskLeads") .FirstOrDefault(p => p.ID == id); // Now that you have your projects and have included the appropriate references, filter things // down based on what you need project.ProjectTasks = project.ProjectTasks.Where(p => p.IsCompleted);
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, September 1, 2015 8:55 AM -
User281315223 posted
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<ProjectRegistry.Models.ProjectTask>' to 'System.Collections.Generic.ICollection<ProjectRegistry.Models.ProjectTask>'. An explicit conversion exists (are you missing a cast?)I'm assuming that this is occurring on the following line as the Where method is going to return an IEnumerable, but your ProjectTasks property is an actual Collection :
project.ProjectTasks = project.ProjectTasks.Where(p => p.IsCompleted);
You could try using the ToList() method which would make the collection a List, which inherits from ICollection :
project.ProjectTasks = project.ProjectTasks.Where(p => p.IsCompleted).ToList();
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, September 2, 2015 8:13 AM
All replies
-
User281315223 posted
I would think it would make more sense to query the actual Task objects themselves if that would be applicable in your situation. This assumes that you actually have a separate table for your ProjectTasks and that you would actually need the tasks themselves :
var completedTasks = db.ProjectTasks.Where(p => p.ProjectID == id && c.IsCompleted);
If that wouldn't work, then you would likely want to apply your includes and then filter those results by only the tasks you are looking for :
var project = db.Project.Include("ProjectTasks.ProjectTaskProgresses,Projecttasks.ProjectTaskLeads") .FirstOrDefault(p => p.ID == id); // Now that you have your projects and have included the appropriate references, filter things // down based on what you need project.ProjectTasks = project.ProjectTasks.Where(p => p.IsCompleted);
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, September 1, 2015 8:55 AM -
User2020942139 posted
When I tried your code, this error appears:
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<ProjectRegistry.Models.ProjectTask>' to 'System.Collections.Generic.ICollection<ProjectRegistry.Models.ProjectTask>'. An explicit conversion exists (are you missing a cast?)
I still cant figure it out :(
Wednesday, September 2, 2015 12:20 AM -
User-446933086 posted
Hi,
You need to change the logic because
c.ProjectTasks.Select
return the list not bool value might be count >0 etc
c.ProjectTasks.Count(a=> a.isCompleted==false)>0
db.Project.Where(c => c.ID == id && c.ProjectTasks.Select(a => a.isCompleted == false)).
Wednesday, September 2, 2015 6:17 AM -
User281315223 posted
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<ProjectRegistry.Models.ProjectTask>' to 'System.Collections.Generic.ICollection<ProjectRegistry.Models.ProjectTask>'. An explicit conversion exists (are you missing a cast?)I'm assuming that this is occurring on the following line as the Where method is going to return an IEnumerable, but your ProjectTasks property is an actual Collection :
project.ProjectTasks = project.ProjectTasks.Where(p => p.IsCompleted);
You could try using the ToList() method which would make the collection a List, which inherits from ICollection :
project.ProjectTasks = project.ProjectTasks.Where(p => p.IsCompleted).ToList();
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, September 2, 2015 8:13 AM