【发布时间】:2019-06-13 01:04:19
【问题描述】:
我很难尝试使用 ASP.net MVC 中的 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).ToList();
我已经加入了这两个表,但现在我的问题是我无法将它放入视图模型中以便能够将其显示到视图中,因为这两个表具有相同的列 transid 所以即使我创建了一个新模型来匹配 linq 表达式的结果值,它不会匹配,因为 transid 不能在同一视图模型中启动两次。你对我该怎么做有什么建议吗?
【问题讨论】:
标签: asp.net-mvc entity-framework linq lambda