左外连接
List<ServicePacksDTO> allServicePacks = new List<ServicePacksDTO>();
using (var db = new DataContext())
{
allServicePacks=(
from sp in db.ServicePacks
join st in db.States.DefaultIfEmpty() on sp.State_id equals st.State_Id
join type in db.ServiceTypes on sp.ServiceType_Id equals type.ServiceType_Id
where
(type.ServiceType_desc.ToLower() == "accepted")
orderby sp.AustState_id
select sp.ToServicePacksDTO(db)).ToList();
}
当前的代码工作正常,直到我尝试对状态进行外连接。有什么方法可以轻松做到这一点吗?
List<ServicePacksDTO> allServicePacks = new List<ServicePacksDTO>();
using (var db = new DataContext())
{
allServicePacks=(
from sp in db.ServicePacks
join st in db.States.DefaultIfEmpty() on sp.State_id equals st.State_Id
join type in db.ServiceTypes on sp.ServiceType_Id equals type.ServiceType_Id
where
(type.ServiceType_desc.ToLower() == "accepted")
orderby sp.AustState_id
select sp.ToServicePacksDTO(db)).ToList();
}
The current code works fine, until I attempt to do an outer join on state. Is there away to do this easily?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要提供更多“工作正常,直到我尝试执行 xx”的详细信息。
什么不起作用?有错误吗?意想不到的结果?
忘记 DTO 投影和 db.ServiceTypes 加入,要在 db.ServicePacks 和 db.States 之间执行 LOJ,请执行以下操作
:首先,确保它有效(应该),然后添加其他连接和投影。
Well firstly, you need to provide a bit more detail that "works fine, until i attempt to do xx".
What doesn't work? Is there an error? Unexpected results?
Forgetting about the DTO projection and
db.ServiceTypes
join, to do a LOJ betweendb.ServicePacks
anddb.States
, do this:Try that first, make sure that works (it should), and then add on your other join and projection.