linq 两个表的关联 不等于
表A
CODE NAME
ZHANGSAN 张三
LISI 李四
WANGWU 王五
表B
ID ACODE VALUE
1 ZHANGSAN 10
2 WANGWU 9
我想取出A表里不在B表里的,所有记录
sql:select A.* FROM A,B where A.CODE!=B.ACODE
LINQ怎么写
------解决方案--------------------var b= (from b in db.B
select b.CODE);
var a = db.A.Where(a=> !a.CODE.Contains(b)).ToList();
------解决方案--------------------a.Select(x => X.CODE).Except(b.Select(x => x.ACODE)).Select(x => a.Single(y => y.CODE == x))
------解决方案--------------------var query=db.A.Where(t=>!db.B.Select(x=>x.CODE.ToString()).Contains(t.CODE.ToString()));