[英]Linq Query Join Tables
I have this Linq Query I run a search function on (DateFrom and DateTo are dateTime objects): 我有这个Linq查询,我在(DateFrom和DateTo是dateTime对象)上运行搜索功能:
var result = from x in DbContext.Transaction_Groups
where (x.Date_Created >= DateFrom && x.Date_Created <= DateTo)
select x;
And these are my tables: 这些是我的表:
I'm trying to join these two tables together so that I can use the .Transaction_Date_Time
instead of the .Date_Created function
that's in my query. 我试图将这两个表连接在一起,以便可以使用
.Transaction_Date_Time
而不是查询中的.Date_Created function
。
My query is trying to determine all the rows between the DateFrom
(user selected value) and the DateTo
(Another user selected value). 我的查询试图确定
DateFrom
(用户选择的值)和DateTo
(另一个用户选择的值)之间的所有行。
var result = from transgroup in DbContext.Transaction_Groups
join cashDep in DbContext.CashDeposit
on transgroup.Group_ID equals cashDep.Group_ID
where (cashDep.Transaction_Date_Time >= DateFrom
&& cashDep.Transaction_Date_Time <= DateTo)
select transgroup
Untested, but should work. 未经测试,但应该可以。 indentation for clarity.
缩进以便清楚。
Do you want to join by Group_ID? 您想通过Group_ID加入吗?
var result = from x in DbContext.Transaction_Groups
join tran in DbContext.CashDeposit on x.Group_ID equals tran.Group_ID
where (tran.Transaction_Date_Time >= DateFrom && tran.Transaction_Date_Time <= DateTo)
select tran;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.