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

表连接后select new 怎么取被连接的表的全字段~~
使用linq连接2个表后,请问下怎么取全字段,因为是外连接,必须用select new 来判断空的情况,但是使用select new,被连接的表字段很多,一一写出来很麻烦的哈,请问各位这个要怎么写??谢谢了哈  
  代码如下所示:select new
  {
  bianhao = t1.Field<string>("bianhao"),
  all_things = t1.Field<int>("all_things"),
  done = t1.Field<int>("done"),
  cui = t1.Field<int>("cui"),
  chong = t1.Field<int>("chong"),
  danwei = t1.Field<string>("danwei"),
  manyi = t1.Field<int>("manyi"),
  bumanyi = t1.Field<int>("bumanyi"),
  yiChaoQi = t1.Field<int>("yiChaoQi"),
  yiYanQi = t1.Field<int>("yiYanQi"),
  yiGongShi = t1.Field<int>("yiGongShi"),
  yiYuJing = t1.Field<int>("yiYuJing"),
  zhuanJieNum = ok == null ? 0 : ok.Field<decimal>("zhuanJieNum")
被链接表还有好多字段,能用一句话搞定吗??

------解决方案--------------------
select new { t1, zhuanJieNum = ok == null ? 0 : ok.Field<decimal>("zhuanJieNum") };

访问的时候:
原来
foreach (var item in query)
{
a = item.bianhao;
b = ...
c = zhuanJieNum;
...
}
现在:
foreach (var item in query)
{
a = item.t1.Field<string>("bianhao");
b = ...
c = zhuanJieNum;
...
}

------解决方案--------------------
select new{t1,ok}