問題
使用 LINQ 做NOT IN篩選資料
解決方法
- var records = from view in db.V_CUSTOMER
- select new
- {
- CUSTOMER_NO = view.CUSTOMER_NO,
- ID_NO = view.ID_NO,
- CUST_NAME = view.CUST_NAME,
- };
- //(取得篩選資料)
- var alreadyApply = (from apply in db.CUSTCLOSEACCAUDIT
- where apply.AUDIT_FINISH_DATE == null
- select apply.CUSTOPENDEPT_GD).Distinct();
- var ApplyList = alreadyApply.ToList();
- //NOT IN寫法
- records = records.Where(o => !ApplyList.Contains(o.CUSTOPENDEPT_GD));
- // IN寫法
- records = records.Where(o => ApplyList.Contains(o.CUSTOPENDEPT_GD));
沒有留言:
張貼留言