这听起来很简单,但我想将下面的sql转换为linq。
Select C.CompanyId, C.CompanyName, CompanyNumber, IsNull(UC.IsActive, 0) as IsActive
From Company as C
Left Join UserCompany UC on UC.CompanyId = C.CompanyId and UC.UserId = '2E34B10C-1BDB-4EF9-ADDF-4C5F949C19B1'
Order by C.CompanyNumber
答案 0 :(得分:1)
这样的事情怎么样?显然,您需要添加实体上下文与我的列表。
var results = (
from c in new List<Company>()
join uc in (
from x in new List<UserCompany>()
where x.UserId == "2E34B10C-1BDB-4EF9-ADDF-4C5F949C19B1"
select x
) on c.CompanyId equals uc.CompanyId into gj
from uc in gj.DefaultIfEmpty()
select new
{
c.CompanyId,
c.CompanyName,
c.CompanyNumber,
uc.IsActive
}
).ToList();