Wcf Rest Service Linq查询因Angular JS应用程序失败

时间:2017-10-23 00:54:31

标签: c# entity-framework linq wcf

我在Angular JS Application中使用Wcf REST服务。我正在使用linq Query遇到一些错误。我在调试模式的后续行中遇到了以下错误。底层提供程序在Commit上失败。

 ReciverAccount.Account_Balance += Convert.ToDecimal(mopneyTransfer.Amount1);
                                dbContextTransaction.Commit();

我试图将一个帐户汇款到另一个帐户,并且应该更新两个帐户的帐户余额并将相应的记录插入数据库但我不能这样做..

以下是调试模式下的错误消息。

System.Data.Entity.Core.EntityException occurred
  HResult=0x80131501
  Message=The underlying provider failed on Commit.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

Inner Exception 1:
ArgumentNullException: Value cannot be null.

这是我的linq查询..

     public bool MoneyTranfer(MoneyTransfer mopneyTransfer)
    {


        //int amount = System.Convert.ToInt32(mopneyTransfer.Amount);
        //int amount1 = System.Convert.ToInt32(mopneyTransfer.Amount1);


        int ID = Convert.ToInt32(mopneyTransfer.Sender_Account_No);
        var foundAccount = (from a in ctx.Current_Account_Details
                            where a.Account_Number.Equals(ID)
                            select a).Distinct().FirstOrDefault();
        if (foundAccount != null)
        {
            //if (amount > 0)
            //{
            using (var dbContextTransaction = ctx.Database.BeginTransaction())
            {

                    var senderAccount = (from a in ctx.Current_Account_Details
                                         where a.Account_Number.Equals(ID)
                                         select a).Distinct().FirstOrDefault();
                    if (senderAccount != null)
                    {

                        senderAccount.Account_Balance -= Convert.ToDecimal(mopneyTransfer.Amount);
                        dbContextTransaction.Commit();
                        ctx.SaveChanges();
                    }

                    int ID1 = Convert.ToInt32(mopneyTransfer.Receiver_Account_No);

                    var ReciverAccount = (from a in ctx.Current_Account_Details
                                          where a.Account_Number.Equals(ID1)
                                          select a).Distinct().FirstOrDefault();

                    if (ReciverAccount != null)
                    {

                        ReciverAccount.Account_Balance += Convert.ToDecimal(mopneyTransfer.Amount1);
                        dbContextTransaction.Commit();

                        ctx.SaveChanges();
                        Current_Account_Deposit cad = new Current_Account_Deposit();
                        cad.Account_Number = Convert.ToInt32(mopneyTransfer.Sender_Account_No);
                        cad.Account_Holder_Name = mopneyTransfer.Sender_Name;
                        cad.Amount = Convert.ToDecimal(mopneyTransfer.Amount);
                        cad.Sort_Code = mopneyTransfer.Sender_Sort_Code;
                        cad.Transcation_Type = mopneyTransfer.Transcation_Type;
                        cad.Date = mopneyTransfer.Date;
                        ctx.Current_Account_Deposit.Add(cad);

                        ctx.SaveChanges();

                        Current_Account_Withdraw caw = new Current_Account_Withdraw();
                        caw.Account_Number = Convert.ToInt32(mopneyTransfer.Receiver_Account_No);
                        caw.Account_Holder_Name = mopneyTransfer.Receiver_Name;
                        caw.Amount = Convert.ToDecimal(mopneyTransfer.Amount1);
                        caw.Sort_Code = mopneyTransfer.Receiver_Sort_Code;
                        caw.Transcation_Type = mopneyTransfer.Transcation_Type1;
                        caw.Date = mopneyTransfer.Date1;
                        ctx.Current_Account_Withdraw.Add(caw);

                        ctx.SaveChanges();
                    }
                    else
                    {
                        dbContextTransaction.Rollback();
                        return false;
                    }
                }

        }  return false;
    }

任何反馈或建议都会有很大的帮助。

0 个答案:

没有答案