日期:2014-05-20 浏览次数:20832 次
static void Main(string[] args)
{
DataTable dt1 = new DataTable();
dt1.Columns.Add("id", typeof(int));
dt1.Columns.Add("name", typeof(string));
DataTable dt2 = new DataTable();
dt2.Columns.Add("id", typeof(int));
dt2.Columns.Add("sex", typeof(string));
for (int i = 0; i < 3; i++)
{
DataRow dr = dt1.NewRow();
dr["id"] = i;
dr["name"] = "table1 " + i;
dt1.Rows.Add(dr);
}
for (int i = 1; i < 4; i++)
{
DataRow dr = dt2.NewRow();
dr["id"] = i;
dr["sex"] = "sex " + i;
dt2.Rows.Add(dr);
}
//var q = dt1.AsEnumerable().Join(dt2.AsEnumerable(), dt1key => dt1key.Field<int>("id"),
// dt2key => dt2key.Field<int>("id"), (dt1key, dt2key) => new
//{
// id = dt1key.Field<int>("id"),
// name = dt1key.Field<string>("name"),
// sex = dt2key.Field<string>("sex")
//});
var q = from member in dt1.AsEnumerable()
join club in dt2.AsEnumerable() on member.Field<int>("id") equals club.Field<int>("id")