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();
}当前代码运行良好,直到我尝试在state上执行外部联接。有没有很容易做到这一点的方法?
发布于 2011-06-08 16:48:05
好的,首先,你需要提供更多的细节,“在我尝试做xx之前,一切都很好”。
什么不起作用?有错误吗?意外的结果?
忘记了DTO投影和db.ServiceTypes连接,要在db.ServicePacks和db.States之间做一个LOJ,请执行以下操作:
var x = (from sp in db.ServicePacks
join st in db.States on sp.State_id equals st.State_id into spst
from x in spst.DefaultIfEmpty()
select new { /* fields */ }
).ToList();首先尝试一下,确保它可以工作(应该可以),然后添加到其他连接和投影上。
https://stackoverflow.com/questions/6275440
复制相似问题