小编Fel*_*JIN的帖子

错误:转换为值类型'System.Int32'失败,因为具体化值为null

我遇到了问题

转换为值类型'System.Int32'失败,因为实现的值为null.结果类型的泛型参数或查询必须使用可空类型.

我已经找到了解决问题的答案,但我找不到相似的案例.

我试图从输入中找出max交易ID .如果帐户没有任何交易,则会导致错误.这两个表之间的关系为tblTransaction.accountId = tblAccount.IdtblTransactionsaccount id

我的控制器:

//GET: Balance

    [Authorize]
    public ActionResult Index()
    {
        string useracc = (string)Session["AccountNumber"];

        var accountInstance = db.Accounts.FirstOrDefault(w => w.AccountNumber.ToString() == useracc);


        List<Transaction> AccountTransactions = db.Transactions.Where(w => w.AccountId == accountInstance.Id&&w.IsCancelled ==false).Select(w => w).OrderByDescending(w => w.Date).ToList();

            var accountStatement = AccountTransactions.Where(w => w.TransactionTypeId == 2 && w.Date.Year >= 2015).OrderByDescending(w => w.Date).ToList();

            var lastTransactionId = db.Transactions.Where(w => w.AccountId == accountInstance.Id && w.IsCancelled == false && w.TransactionTypeId == 2 && w.Date.Year >= …
Run Code Online (Sandbox Code Playgroud)

c# linq asp.net-mvc entity-framework

2
推荐指数
1
解决办法
7394
查看次数

标签 统计

asp.net-mvc ×1

c# ×1

entity-framework ×1

linq ×1