我试图在 razor 中使用 linq 从数据库中返回一个数值。当我尝试什么都没有返回。这是我所做的一个例子。未打印的变量是“grad_year”
@{
var trust = new trusteeEntities();
var former = (from g in trust.Members
where g.status == "Former"
orderby g.lname ascending
select g);
var pos = 0;
foreach (var f in former)
{
<div class="member">
<h6>@f.fname @f.lname @if (f.grad_year != null) { @string.Format("'{0:00}", f.grad_year); } @if (f.deceased == true){@Html.Raw("**")}</h6>
</div>
}
}