GridView でボタンを 1 回クリックするだけで、すべてのトランザクション データを入力しています。ただし、データベースのトランザクション テーブルにはディメンション テーブル (たとえば、アカウント テーブル) のデータが含まれていません。たとえば、トランザクション テーブルには AccountID が含まれていますが、アカウント テーブルから取得する必要がある AccountName プロパティはありません。DataAccess レイヤーでは、メソッド (GetAllTransactions()) に AccountID の Transaction テーブルと Account テーブルの間の結合が含まれていますが、account.AccountName を選択しようとすると機能しません。
AccountID が一致する Transaction テーブルからいくつかのテーブルを表示し、Transaction テーブルの AccountID の代わりに AccountName 列を表示するだけです。
DataAccess メソッドは次のようになります。
public static IEnumerable<Transaction>GetAllTransactions()
{
List<Transaction> allTransactions = new List<Transaction>();
using (var context = new CostReportEntities())
{
allTransactions = (from t in context.Transactions
join account in context.Accounts on t.AccountID equals account.AccountID
select t).ToList();
}
return allTransactions;
}
.aspx ページの背後にあるコードは次のとおりです。
protected void _UIButtonSubmit_Click(object sender, EventArgs e)
{
IEnumerable<Transaction> transactions = ts.GetAllTransactions();
_UITransactionGridView.DataSource = transactions;
_UITransactionGridView.DataBind();
_UITransactionGridView.PageIndex = 0;
}
以下でもいくつか試してみましたが、LINQのアイデアが得られません。以下はエラーになります。
...select new {t.*, account.AccountName}).ToList();
1 つの GridView に複数のテーブルからデータを入力するタスクを機能させるには、どの方向を見ればよいかという方向性が必要です。ありがとう。