给定两个表,Project 和 Expense 以及字段
Project.ProjectKey
Project.Budget
Expense.ProjectKey
Expense.Amount
我将如何编写一个 Linq 语句来给出包括Project.Budget
减去所有在内的结果我将Expense.Amounts?
如何在 MVC 4 视图中引用该引用?
这是我所拥有的......但它并不接近:
var projects = from s in db.Project
join d in db.Expense
on s.ProjectKEY equals d.ProjectKEY
select s;
帮助表示赞赏!
风景:
@model IEnumerable<TETS_DAL.Project>
@{
ViewBag.Title = "Projects";
}
<h2>All Projects</h2>
<p>
@Html.ActionLink("Create New Project", "Create")
</p>
@using (Html.BeginForm())
{
<table style="padding: 5px 5px 5px 5px;">
<tr>
<th>
<!--@Html.DisplayNameFor(model => model.ProjectKEY)-->
</th>
<th>Project<br />
Number
</th>
<th>Office
</th>
<th>Project<br />
Description
</th>
<th>Start<br />
Date
</th>
<th>End<br />
Date
</th>
<th>Current<br />
Period<br />
Start
</th>
<th>Current<br />
Period<br />
End
</th>
<th>Total<br />
Budget
</th>
<th>Total<br />
Budget<br />
Balance
</th>
<th>Current<br />
Budget
</th>
<th>Current<br />
Budget<br />
Balance
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.HiddenFor(modelItem => item.ProjectKEY)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProjectNumber)
</td>
<td>
@Html.DisplayFor(modelItem => item.Division.DivisionName)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProjectDescription)
</td>
<td>
@String.Format("{0:d}", item.StartDate)
</td>
<td>
@String.Format("{0:d}", item.OverallEndDate)
</td>
<td>
@String.Format("{0:d}", item.CurrentPeriodStartDate)
</td>
<td>
@String.Format("{0:d}", item.CurrentPeriodEndDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.OverallTechnologyBudget)
</td>
<td>
@* @Html.DisplayFor(modelItem => item.ExpenseItem.ExpenseAmount)*@
</td>
<td>
@Html.DisplayFor(modelItem => item.CurrentPeriodBudget)
</td>
<td></td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ProjectKEY }) |
@Html.ActionLink("Details", "Details", new { id = item.ProjectKEY }) |
@Html.ActionLink("Expenses", "Index", "ExpenseItem", new { projectSearchString = item.ProjectNumber }, null)
</td>
</tr>
}
</table>
}