[Table(Name = " Orders " )] public class Orders { [Column(DbType = "nchar(5) null")] public string CustomerID; [Column(DbType = "int null")] public int EmployeeID; [Column(DbType = "datetime null")] public string OrderDate; } [Table(Name = " Employees " )] public class Employees { [Column(DbType = "int not null")] public int EmployeeID; [Column(DbType = "nvarchar(10) not null")] public string FirstName; [Column(DbType = "nvarchar(30) null")] public string Title; }
实现 public DataSet createDataTable() { DataContext context = new DataContext(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString); Table<LINQtoDS_WebApp.BussinessEntity.Orders> orderTable = context.GetTable<LINQtoDS_WebApp.BussinessEntity.Orders>(); Table<LINQtoDS_WebApp.BussinessEntity.Employees> empTable = context.GetTable<LINQtoDS_WebApp.BussinessEntity.Employees>(); var query1 = from o in orderTable where o.CustomerID.StartsWith("V") select o; var query2 = from es in empTable select es; DataTable orderDataTable = new DataTable("OrdersTable"); DataTable empDataTable = new DataTable("EmployeesTable"); DataSet ds = new DataSet(); ds.Tables.Add(DataSetLinqOperators.CopyToDataTable(source, orderDataTable, LoadOption.PreserveChanges)); ds.Tables.Add(DataSetLinqOperators.CopyToDataTable(source2, empDataTable, LoadOption.PreserveChanges)); return ds; }
你把这个 的类复制过来.放在一起就能实现了; 再在页面去和GridView绑定就可以拉