[英]Linq query to select data from table and join 2 tables
I am trying to select
everything from a table and then make a join with two other tables, from which I need just some of the columns. 我试图从一个表中select
所有内容,然后与其他两个表进行联接,而我只需要其中一些列。 The final list will be populated into a DevExpress GridControl
. 最终列表将填充到DevExpress GridControl
。 The main table that I take the data from has these columns: 我从中获取数据的主表具有以下列:
Id | ScheduleId | AccountId | Description
I can easily select everything from this table and return. 我可以轻松地从此表中选择所有内容并返回。 Here is my list: 这是我的清单:
public IList<StatusDescription> getStatusDescription()
{
var listOfItems = from e in context.StatusDescription select e;
return listOfItems.ToList<StatusDescription>();
}
The other two tables are Schedules and Accounts, they look as follows: 其他两个表是时间表和帐户,它们如下所示:
Id | ScheduleName | DateFrom | DateTo
and 和
Id | AccountName | AccountCode
I would like to join the DateFrom
and DateTo
from the Schedule
table and the AccountCode
from the Account
table. 我想加入Schedule
表中的DateFrom
和DateTo
以及Account
表中的AccountCode
。 Is it possible to get all that into a single list. 是否有可能将所有内容合并到一个列表中。 I can easily bind it later to the GridControl
我可以稍后将其轻松绑定到GridControl
var listOfItems = from e in context.StatusDescription
join s in context.Schedules on e.ScheduleId equals s.Id
join a in context.Accounts on e.AccountId equals a.Id
select new
{
Description = e.Description,
ScheduleStart = s.DateFrom,
ScheduleEnd = s.DateTo,
AccountCode = a.AccountCode
}
var Query = from p in context.StatusDescription select new { p.Id, p.Description, p.Schedule.DateFrom, p.Schedule.DateTo, p.Account.AccountCode };
希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.