Linq问题让我疯狂从子表的子项中恢复数据(Linq Problem make me crazy retreve Data from Child Of Child Table)

   IT问题网   2020-06-30 00:00:00

问 题

我有一个小linq问题让我发疯

我是编程领域的新手"小程序员"。

plz我需要快速,简单的回答使用我的编码风格。

我的问题是

假设我有这个数据库

 城市表:city_id为 pk ,city_name。 
部门表:city_id为 fk ,dept_id为 pk ,dept_name。
员工表:dept_id fk,emp_id为pk,emp_name。
1-如果我在字符串c中有城市名称;

我想要撤回所有在城市中放置城市名称的城市名称中的所有相关员工姓名在字符串c中;

2-如果我在字符串e中有员工姓名;

我想要撤销该员工所在的城市名称;

我的编码风格是:

--------------------- -------------------------------------------------- ------------

使用datacontext就像我的简单示例一样,retreve具有员工姓名的部门名称在字符串e中;



  public   partial   _default:system.web.ui.page 
{
prodatacontext m = new prodatacontext(); // 数据库对象
protected void page_load( object sender,eventargs e)
{
string e;
string d = m.departments.where(x = gt; x.dep_id == m.employees.where(n = gt; n.emp_name == e)。 single ()。 dep_id)。 single ()。dep_name;
}

}


--------------------- -------------------------------------------------- -------------



thanx .....





[编辑]整理的代码块 -originalgriff [/ edit]

解决方案

  //  解决方案编号1 :(获取员工) 
dataclasses3datacontext db = new dataclasses3datacontext();
var tbl = 来自 p db.employees
其中 p.department.city.city_name == txtcityname.text
选择 p;


// 解决方案编号2 :(获取城市名称)
dataclasses3datacontext db = new dataclasses3datacontext();
var 来自 db.employees
其中
p.emp_name == txtemployename.text
选择 p)。选择(p = gt; p.department.city);
datagridview1.datasource = tbl;




希望这对你有所帮助

hamid noahdi

标签:问题疯狂子项中恢复数据



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

保留wpf中的菜单(custmized the menu in wpf)

problem i want customize the menu when i click the menu i ...

如何在asp.net 3.5中使用图表控件(how to use chart control in asp.net 3.5)

problem how to use chart control in asp.net 3.5 solution ...

在wpf中的窗口标题栏上双击事件(double click event on window title bar in wpf)

problem i want to implement double click event on title b ...

批处理文件可以保留在内存中(Can Batch File Hold In Memory)

problem i was wondering...... i have a batch ...

用于在C ++中的开源PDF库中读取PDF文件的代码(Code for reading a PDF file in Open Source PDF Libraries in C++)

problem i want the code for reading a pdf file and store ...

MFC应用程序中RichEdit控件的问题(Problem with RichEdit control in MFC application)

problem in my application i am using crichedi ...

如何为每个IP地址创建线程?(How to create threads to each Ip address)

problem good morning friends, i am currently ...

职业生涯在DotNet中呼唤我(Career Call for Me In DotNet)

problem hi all, i''m working as software eng from past o ...

从应用程序备份数据库(take backup of database from application)

problem hi all, i have a database named mydb ...

如何在客户端系统中维护我们的数据库(how to maintain our database in client system)

problem hello iam developing windows application and my ...

C#发送电子邮件SMTP问题(C# sending email SMTP problems)

problem dears i am using visual studio 2008 3 ...

需要帮助使用opengl在c ++中构建迷宫(Need help in building maze in c++ using opengl)

problem this is my code for solution path, i used random ...

使用文本框将一个选项卡值添加到另一个选项卡。(one tab value to another tab both using text box.)

problem how to assign one tab value to another tab if bot ...

使用WSAsy-Model的Win32套接字(Win32 Socket using WSAsy-Model)

problem hi !i want to use the wsaasyncselect ...

一次单击添加空白记录(one click add blank record)

problem dear sir, when was clicking edit link button ther ...

关于sql'列表的问题(the problem which is about listing of sql')

problem i want to get 3 datas which has been added lastly ...

DataGridView绑定源datacontext.ExecuteQuery allowusertoaddrows已禁用(DataGridView Binding Source datacontext.ExecuteQuery allowusertoaddrows disabled)

problem using the following code: iqueryable data = db.e ...

我想在每个页面上显示用户名(I want to display username on every page)

problem can i use loginview control without login control ...

解释如何重载.ToString()方法......(Explain how to overload .ToString() method...)

problem help me friends... :) thanks in advance... soluti ...

UserControl编辑对象(UserControl to edit an object)

problem hello, i have a usercontrol that has some fields ...