public static class ExtMethods { public static IEnumerable <mySimpleType> Cast <MySimpleType>(this DataTable obj) { List <mySimpleType> ret = new List <mySimpleType>(); foreach (DataRow row in obj.Rows) ret.Add(new mySimpleType() { Name = row["name"], Date = row["date"], Doc = row["doc"] }); return ret; } }
public class mySimpleType { public string Name; public DateTime Date; public List <System.Xml.XmlDocument> Doc; }
在主程序中,可以这样写查询了:
DataSet abc; //todo: 设置abc的数据 var search = from r in abc.Tables["SimpleTable"].Cast <mySimpleType>() where r.Name.StartsWith("wu") && r.Date >= DateTime.Parse("2008/1/10") select r;