我正在尝试使用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**
}
}
答案 0 :(得分:1)
您不需要使用2个单独的查询,只需通过连接2个表并从结果集中选择所有必需的属性来构建单个查询。然后,您可以将其放在IEnumerable
对象中并使用JSON serializer从查询结果返回JSON响应:
public string TranscationDetails(string Account_Number)
{
using (HalifaxDatabaseEntities context = new HalifaxDatabaseEntities())
{
var CombinedQuery = (from x in context.Current_Account_Deposit
join y in context.Current_Account_Withdraw
on x.Account_Number equals y.Account_Number
where x.Account_Number == Convert.ToInt32(Account_Number)
select new {
x.Account_Number,
// put other properties here
}).ToList();
var js = new System.Web.Script.Serialization.JavaScriptSerializer();
return js.Serialize(CombinedQuery); // return JSON string
}
}