var possibleTPMs = (from ui in db1.Users
from org in db2.Orgs.Where(o => o.OrgId == ui.OrgId && !o.DeletedFlag).DefaultIfEmpty()
where !ui.DeletedFlag && ui.ActiveFlag && ui.OrgId == 1 && ui.UserId != 1
select new { ui.UserId, ui.LastName, ui.FirstName }).ToList();
上面是示例LINQ但有错误,我如何加入来自两个不同数据库的这两个表。
答案 0 :(得分:0)
加入两张桌子'你只需使用以下语法加入它们。你不应该使用wheres
进行任何复杂的连接 var possibleTPMs = (from ui in db1.Users
join org in db2.Orgs on ui.id equals org.id
select new { ui.UserId, ui.LastName, ui.FirstName }).ToList();