【问题标题】:How to display LINQ lamda expression result with Join to a View using ASP.Net MVC?如何通过使用 ASP.Net MVC 加入视图来显示 LINQ lambda 表达式结果?
【发布时间】:2019-06-10 09:26:24
【问题描述】:

我在将 linq lambda 表达式的结果显示到视图时遇到问题。

这是我的代码:

   var idSearchJoin = payoutdb.payout_transaction    // your starting point - table in the "from" statement
                .Join(payoutdb.payout_remittance, // the source table of the inner join
                transaction => transaction.transid, // Select the primary key (the first part of the "on" clause in an sql "join" statement)
                remit => remit.transid,   // Select the foreign key (the second part of the "on" clause)
                (transaction, remit) => new { Transaction = transaction, Remit = remit }) // selection
                .Where(transactremit => transactremit.Transaction.senderRefId == searchTxt);

我在这里使用的连接使这个问题变得复杂,所以现在我不知道如何将数据传输到视图,就像没有连接时那样。

【问题讨论】:

  • .Select(x => x.Transaction)?而且:不要使用join,而是使用导航属性。
  • 你能举例说明我应该怎么做吗?我想向视图显示 2 个表的两个值。

标签: asp.net-mvc entity-framework linq lambda


【解决方案1】:

var idSearchJoin = payoutdb.payout_transaction.Include(x => x.payout_remittance).Where(x => x.payout_remittance.Any(y => y.senderRefId == searchTxt)); 试试这个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-10
    • 1970-01-01
    • 1970-01-01
    • 2011-05-24
    • 2011-08-08
    • 2016-07-01
    • 1970-01-01
    相关资源
    最近更新 更多