如何在LINQ中创建关系 [英] How can I create relations in LINQ

查看:88
本文介绍了如何在LINQ中创建关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是使用Ado.net的以下代码,但我想将其转换为Linq

Here the following code using Ado.net but i want to convert it into Linq

SqlConnection con1 = new SqlConnection(con);

SqlDataAdapter dadCats = new SqlDataAdapter("select  menuid,menuname,imageurl,parentmenuid from  menus where menutype= 'mainmenu' and  menulevel='0' and menuid='5'", con1);

SqlDataAdapter dadCats1 = new SqlDataAdapter("select menuid,menuname, parentmenuid,urlname,imageurl from  menus where menutype= 'submenu' and menulevel='1' and parentmenuid='5'", con1);

SqlDataAdapter dadCats2 = new SqlDataAdapter("select menuid,menuname, parentmenuid,urlname,imageurl from  menus where menutype= 'submenu' and menulevel='2'and parentmenuid in(6,7,8,9,10)", con1);
DataSet dst = new DataSet();

dadCats.Fill(dst, "Menu");
dadCats1.Fill(dst, "Menu1");
dadCats2.Fill(dst, "Menu2");

dst.Relations.Add("Children", dst.Tables["Menu"].Columns["menuid"], dst.Tables["Menu1"].Columns["parentmenuid"]);
dst.Relations.Add("Children1", dst.Tables["Menu1"].Columns["menuid"], dst.Tables["Menu2"].Columns["parentmenuid"]);

推荐答案

您正在要求我们为您完成工作.我建议您阅读有关LINQ的一些书籍和/或文章.这是一个很好的起点: LINQ页面.这是另一个:代码项目文章:LINQ简介第1部分,共3部分.
You are asking us to do your work for you. I suggest you read some books and/or articles on LINQ. Here is a good starting point: LINQ Page. Here is another: Code Project Article: LINQ Introduction Part 1 Of 3.


这篇关于如何在LINQ中创建关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆