我正在尝试将以下SQL实现到Linq,但我无法做到。
select Isnull(a.Code,b.Code), Isnull(a.Description,b.Description) from table1 b
FULL OUTER JOIN table2 b On a.Code = b.Code AND b.Id = xx
我尝试执行两个单独的left join
和union
语句,但我无法处理IsNull
检查。
这是我尝试过的代码:
var leftData = (from a in entities.tbl1
join b in entities.tbl2 on a.Code equals b.Code into temp
orderby a.Code
from b1 in temp.DefaultIfEmpty()
where b1.Id == xxx && a.Code.StartsWith(prefixText)
select new DCodes()
{
ID = a.ID,
CodeName = a.Code
}).ToList();
var rightData = (from b in entities.tbl2
join a in entities.tbl1 on b.Code equals a.Code into temp
orderby b.Code
where b.Id == xxx && b.Code.StartsWith(prefixText)
from b1 in temp.DefaultIfEmpty()
select new DCodes()
{
ID = b.ID,
CodeName = b.Code
}).ToList();
var a = leftData.Union(rightData).Distinct().ToList();