Linq查询因Concat运算符失败

问题描述 投票:0回答:1

我试图开发银行系统。我试图将三个表记录连接到单个表中。但问题是当我编译它时我得到了以下错误。

错误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
            }
        }

这是数据库记录enter image description here

这是模型类。 enter image description here

sql-server entity-framework linq wcf
1个回答
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; }
}
© www.soinside.com 2019 - 2024. All rights reserved.