代码之家  ›  专栏  ›  技术社区  ›  Mohammad

Linq查询因Concat运算符而失败

  •  0
  • Mohammad  · 技术社区  · 8 年前

    我正在努力发展银行体系。我试图将三个表记录连接到一个表中。但问题是,当我编译它时,我得到了以下错误。

    错误CS1929“IEnumerable<>'不包含“Concat”和“best extension method重载”Queryable的定义。混凝土(&L)&燃气轮机;(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

    1 回复  |  直到 8 年前
        1
  •  1
  •   Worthy7    8 年前
     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; }
    }