我有2个表并使这个连接工作正常我可以将它绑定到数据网格视图(在winforms中)但我如何访问结果数据 by foreach(如何访问row [0] [1],如数据表)??
void Testmethod()
{
IEnumerable<object> result;
using (var context = new TestDBEntities())
{
result = (from a in context.Table1
join b in context.Table2
on a.ID equals b.Id
select new { b.Id ,b.name });
}
}
感谢所有
答案 0 :(得分:0)
这与你提出的要求略有不同,但可能同样适用。
IEnumerable<dynamic> result;
using (var context = new TestDBEntities())
{
result = (from a in context.Table1
join b in context.Table2 on a.Id equals b.Id
select new { b.Id, b.name }).ToList();
}
foreach (dynamic resultEntry in result)
Console.Out.WriteLine("ID:" + resultEntry.Id + " name: " + resultEntry.name);
我希望这足够好;)