【发布时间】:2018-05-29 06:07:40
【问题描述】:
我正在尝试使用 Concat 合并两个 linq 查询。但是当我编译查询时,我收到两个错误。
IQueryable' 不包含“Concat”的定义,并且最佳扩展方法重载“ParallelEnumerable.Concat(ParallelQuery, IEnumerable)”需要“ParallelQuery”类型的接收器
第二个错误是方法所有代码不返回所有路径值
这是我的界面。
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
//BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/TranscationDetails/{Account_Number}")]
string TranscationDetails(string Account_Number);
这是实现。
public string TranscationDetails(string Account_Number)
{
using (HalifaxDatabaseEntities context = new HalifaxDatabaseEntities())
{
var DepositQuery = from x in context.Current_Account_Deposit
where x.Account_Number == Convert.ToInt32(Account_Number)
select x;
var WithdrawQuery = from x in context.Current_Account_Withdraw
where x.Account_Number == Convert.ToInt32(Account_Number)
select x;
var merge = DepositQuery.Concat(WithdrawQuery);//**Error on this line**
}
}
【问题讨论】:
-
var merge = DepositQuery.Union(WithdrawQuery);(如果Current_Account_Deposit和Current_Account_Withdraw具有完全相同的结构,则可用)。您还需要为TranscationDetails方法返回一个字符串(目前它缺失,或者如果您返回查询结果使用IQueryable)。 -
使用
Union()方法得到什么结果?要执行Union,两个查询结果必须具有相同的列列表。如果两个结果集不同,则使用ToList()创建IEnumerable对象,然后使用Union()。 -
我想从 Current_Account_Deposit 和 Current_Account_Withdraw 表中选择所有带有帐号的记录,然后将它们合并到单个查询中
-
尝试使用
Join方法:from x in context.Current_Account_Deposit join y in context.Current_Account_Withdraw on x.AccountNumber equals y.AccountNumber where x.Account_Number == Convert.ToInt32(Account_Number) select ...; -
Join方法已经奏效了吗?你想要TranscationDetails方法的返回类型到底是什么(我假设你想要IQueryable,但你将它定义为字符串)?
标签: c# mysql entity-framework linq