I have the following entities:
Clients
— ClientID
— ClientName
Contractor
— ContractorID
— ContractorName
PreferredContractors
— PreferredContractorID
— ClientID
— ContractorID
So I have a list of clients and contractors. The clients prefer to work with certain contractors than the others. I want to build a LINQ to Entity query which pulls all the contractors with a boolean field indicating whether the contractor is preferred or not.
public IQueryable<PreferredContractor> GetPreferredContractors(int clientID)
{
var preferredContractors = from c in db.Contractors
from pc in db.PreferredContractors.DefaultIfEmpty()
select new PreferredContractor
{
ContractorID = c.ContractorID,
ContractorName = c.ContractorName,
IsPreferred = // This is where I need help
};
return preferredContractors;
}
How can I determine if the contractor is preferred or not?
1 Answer