日期:2014-05-20  浏览次数:20837 次

LINQ 高手请出现。LINQ难题: 序列中不包含任何元素。
var query = 
  from row in tbl.AsEnumerable() 
  let criterion = otherList.First <myClass>(o => o.ID == n) 
  where criterion !=null 
  select myFun(row) 

  private DataRow assembResult(DataRow row) 
  { 
  row["FieldN"] = "nn1"; 
  return row;
  } 

上面这句LinQ为什么运行的时候提示错误:序列中不包含任何元素。

------解决方案--------------------
otherList.First <myClass>(o => o.ID == n) 
=>
otherList.FirstOrDefault <myClass>(o => o.ID == n) 

试试