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

linq转换
DataSet ds = dbsql.Query("select State from Articles");
         if (ds.Tables[0].Rows.Count > 0)
         {
            for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
             {
                 int states = Convert.ToInt32(ds.Tables[0].Rows[i]["State "]);
             }
         }

麻烦帮我转成linq的写法。谢谢
------解决方案--------------------
ds.Tables[0].AsEnumerable().ToList().ForEach(c => states= c.Field<int>("State"));
------解决方案--------------------
 List<int> mylist = ds.Tables[0].AsEnumerable().Select(c => c.Field<int>("EmployeeID")).ToList<int>();

------解决方案--------------------
List<int> query=db.Articles.Select(a=>a.State).ToList();