我尝试使用linq显示来自两个表的数据,没有错误,但我认为我的数据没有到达视图。在调试代码时,我看到linq处理了正确的信息。运行应用程序后,不会出现任何数据,只显示@Html.DisplayNameFor。
var details = from l in db.LogDetails.ToList()
join a in db.AuditLog.ToList()
on l.AuditLogId equals a.AuditLogId into b
from d in b.DefaultIfEmpty()
where d.RecordId.Equals(id)
select new AuditLogDetail
{
PropertyName = l.PropertyName,
OriginalValue = l.OriginalValue,
NewValue = l.NewValue
};
return View(details.ToList());全景式
@model IEnumerable<TrackerEnabledDbContext.Common.Models.AuditLogDetail>
@{
ViewBag.Title = "Lista zgłoszeń";
}
<h2>Lista zgłoszeń</h2>
<p>
@Html.ActionLink("Nowe zgłoszenie", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.PropertyName)
</th>
<th>
@Html.DisplayNameFor(model => model.OriginalValue)
</th>
<th>
@Html.DisplayNameFor(model => model.NewValue)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.PropertyName)
</td>
<td>
@Html.DisplayFor(modelItem => item.OriginalValue)
</td>
<td>
@Html.DisplayFor(modelItem => item.NewValue)
</td>
</tr>
}
</table>返回视图调试后显示的信息的屏幕截图(details.ToList());
我将linq查询更改为:
var r = from s in db.LogDetails
select s;而且表中的每个值都正确显示,但是我需要根据另一个表筛选数据,所以当我尝试下面的代码时,会出现一个错误:
无法创建“System.Object”类型的常量值。在此上下文中只支持基本类型或枚举类型。
代码:
var r = from s in db.LogDetails
join l in db.AuditLog
on s.AuditLogId equals l.AuditLogId
where l.RecordId.Equals(id)
select s;我已经将其更改为==,但是它不会编译。
发布于 2019-01-17 00:15:58
尝试将.Equals替换为==
var r = from s in db.LogDetails
join l in db.AuditLog
on s.AuditLogId equals l.AuditLogId
where l.RecordId == id
select s;https://stackoverflow.com/questions/54217155
复制相似问题