左外连接 LINQ To Entities
我有以下实体:
客户
-- 客户端ID
-- 客户名称
承包商
-- 承包商ID
-- 承包商名称
首选承包商
-- 首选承包商 ID
-- 客户端ID
-- ContractorID
所以我有一份客户和承包商的列表。与其他承包商相比,客户更喜欢与某些承包商合作。我想构建一个 LINQ to Entity 查询,该查询使用布尔字段来提取所有承包商,指示该承包商是否是首选。
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;
}
我如何确定承包商是否是首选承包商?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)