Reputation: 625
Using the following example I'm attempting to retrieve all Jobs where IsAssigned is false.
public class Job {
public int JobId { get; set; }
...
public virtual ICollection<Bid> Bids { get; set; }
}
public class Bid {
public int BidId { get; set; }
public int JobId { get; set; }
...
public bool IsAssigned { get; set; }
...
public virtual Job Job { get; set; }
}
Below is the View method for displaying the available jobs.
public ViewResult AvailableJobs() {
var jobs = db.Jobs.Include(j => j.Bids.Select(b => b.IsAssigned));
return View(jobs.ToList());
}
This produces the following error
A specified Include path is not valid. The EntityType 'MvcTuition.DAL.Bid' does not declare a navigation property with the name 'IsAssigned'.
Any ideas of how I can return all Jobs where IsAssigned is false?
Upvotes: 0
Views: 102
Reputation: 32437
Try
var jobs = db.Jobs.Include(j => j.Bids).Where(j => j.Bids.Any(b => b.IsAssigned));
Upvotes: 1
Reputation: 18069
var jobs = db.Jobs.Include(j => j.Bids.Where(b => b.IsAssigned));
Upvotes: 1