[英]Left Join Entity Framework not running
我正在嘗試進行“左加入”。
但是,只有當我在“兩個表中”都有信息時,該命令才會返回某些內容。
吼叫我的功能
public IList<ClientWorkFlowReadModel> GetWorkFlow(int idClient)
{
try
{
using (GvisaContext db = new GvisaContext())
{
//Disable de proxy tracking for prevent error in json convertion
db.Configuration.ProxyCreationEnabled = false;
var clientServiceWorkFlows = db.ServicesWorkFlow
.Join(db.ClientsServicesWorkFlow,
swf => swf.IdServiceWorkFlow,
cswf => cswf.IdServiceWorkFlow,
(swf, cswf) =>
new { swf, cswf })
.Select(x => new ClientWorkFlowReadModel {
Title = x.swf.Title,
IdClient = x.cswf.IdClient,
IdService = x.swf.IdService,
IdClientServiceWorkFlow = x.cswf.IdClientServiceWorkFlow,
Description = x.swf.Description,
Active = x.swf.Active,
DateUpdate = x.cswf.DateUpdate
}
).Where(y => y.IdClient == idClient).ToList();
return clientServiceWorkFlows;
}
}
catch (Exception ex)
{
throw ex;
}
我需要這樣做:
SELECT * FROM dbo.Clients z
INNER JOIN dbo.ClientsServices y on y.idClient=z.idClient
INNER JOIN dbo.ServicesWorkFlow a on a.IdService=y.IdService
LEFT JOIN ClientsServicesWorkFlow b on b.IdClientServiceWorkFlow=a.IdServiceWorkFlow
WHERE z.IdClient=3
謝謝!!!
var clientServiceWorkFlows = (from z in db.Clients
join y in db.ClientsServices on z.idClient equals y.idClient
join a in db.ServicesWorkFlow on y.IdService equals a.IdService
join ClientsServicesWorkFlow b on a.IdServiceWorkFlow equals b.IdClientServiceWorkFlow into g
from x in g.DefaultIfEmpty()).Select([... what you want]
).Where(y => y.IdClient == idClient).ToList();
嘗試以上。 讓我知道它是否有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.