永发信息网

linq to sql

答案:1  悬赏:30  手机版
解决时间 2021-05-10 05:04
  • 提问者网友:雾里闻花香
  • 2021-05-09 10:36
表结构 autoid typename parentid id列 名称 父id sql语句: select t1.autoid as t1id, t1.typename as t1tn, t2.autoid as t2id, t2.typename as t2tn, t3.autoid as t3id, t3.typename as t3tn from gametype as t1, gametype as t2, gametype as t3 where t1.autoid=22 and t1.parentid=t2.autoid and t2.parentid=t3.autoid 用linq to sql 怎么写啊??
最佳答案
  • 五星知识达人网友:轮獄道
  • 2021-05-09 11:39

假设你的三个表全部都已经LINQ化(生成了对应的类,此类的DataContext叫做DBDataContext):


using (DbDataContext dbc = new DbDataContext())
{
 var result = from t1 in dbc.Table1
    from t2 in dbc.Table2
    from t3 in dbc.Table3
    where (t1.autoid=22 && t1.parentid=t2.autoid &&
t2.parentid=t3.autoid)
    select new
   {
    t1id = t1.autoid,
    t1tn = t1.typename,
    t2id = t2.autoid,
    t2tn = t2.typename,
    t3id = t3.autoid,
    t3tn = t3.typename


   };
}

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯