我正在尝试开发银行系统。我试图将三个表记录连接到单个表中。但问题是当我编译它时我遇到了以下错误。
错误CS1929'IEnumerable<>'不包含'Concat'的定义和最佳扩展方法重载'Queryable.Concat<>(IQueryable<>,IEnumerable<>)'需要'IQueryable<> 类型的接收器
这是Linq查询。
public string TranscationDetails(string Account_Number)
{
var accountNumber = int.Parse(Account_Number);//It could be better to use TryParse
using (HalifaxDatabaseEntities context = new HalifaxDatabaseEntities())
{
var q1 = context.Current_Account_Deposit.Where(x => x.Account_Number == accountNumber).Select(w => new
{
w.Account_Number,
Deposit = (decimal?)null,
Withdrawal = (decimal?)w.Amount,
w.Date
}).ToList();
var q2 = context.Current_Account_Withdraw.Select(d => new
{
d.Account_Number,
Deposit = (decimal?)d.Amount,
Withdrawal = (decimal?)null,
d.Date
}).OrderBy(r => r.Date).ToList();
var q3 = context.Current_Account_Details.Select(e => new
{
//You should perform same anonymous type which you want to concat
Account_Number = e.Account_Number,
Deposit = (decimal?)e.Account_Balance,
Withdrawal = (decimal?)null,
e.Account_Fees
}).ToList();
var inOut = q1.Concat(q2).Concat(q3).ToList();**//Error on this line**
var js = new System.Web.Script.Serialization.JavaScriptSerializer();
return js.Serialize(inOut); // return JSON string
}
}
答案 0 :(得分:1)
public string TranscationDetails(string Account_Number)
{
var accountNumber = int.Parse(Account_Number);//It could be better to use TryParse
List<AccountTransaction> accountTransactions = new List<AccountTransaction>();
using (HalifaxDatabaseEntities context = new HalifaxDatabaseEntities())
{
accountTransactions.AddRange(context.Current_Account_Deposit.Where(x => x.Account_Number == accountNumber).Select(w => new AccountTransaction
{
AccountNumber = w.Account_Number,
Deposit = 0,
Withdrawal = w.Amount,
Date = w.Date,
Fee = 0
}).ToList());
accountTransactions.AddRange(context.Current_Account_Withdraw.Select(d => new AccountTransaction
{
AccountNumber = d.Account_Number,
Deposit = d.Amount,
Withdrawal = 0,
Date = d.Date,
Fee = 0
}).OrderBy(r => r.Date).ToList());
accountTransactions.AddRange(context.Current_Account_Details.Select(e => new AccountTransaction
{
//You should perform same anonymous type which you want to concat
AccountNumber = e.Account_Number,
Deposit = e.Account_Balance,
Withdrawal = 0,
Date = null,
Fee = e.Account_Fees
}).ToList());
var inOut = accountTransactions;
var js = new System.Web.Script.Serialization.JavaScriptSerializer();
return js.Serialize(inOut); // return JSON string
}
}
public class AccountTransaction
{
public int AccountNumber { get; set; }
public decimal Deposit { get; set; }
public decimal Withdrawal { get; set; }
public string Date{ get; set; }
public decimal Fee { get; set; }
}