我的 proc 返回所有结果,但 MVC 显示查找为空。
我有一个视图,其中 for 循环的“网格”如下所示:
@foreach (var item in Model) {
<tr>
<td>@Html.ActionLink(item.Headline, "ViewDetails", "Advisory", new { id=item.AdvisoryId }, "")</td>
<td>@item.AdvisoryStartDate.ToShortDateString()</td>
<td>@item.AdvisoryType.AdvisoryType</td>
<td>@item.AdvisoryProvider.AdvisoryProvider</td>
<td>@item.AdvisoryCategory.AdvisoryCategory</td>
</tr>
}
最后三个字段是查找。我最初用这个控制器调用填充了它:
var advisories = db.Advisories.Include(i => i.AdvisoryType)
.Include(i => i.AdvisoryProvider)
.Include(i => i.AdvisoryCategory)
.OrderByDescending(i => i.AdvisoryStartDate);
ViewData["Advisories"] = advisories;
但是我现在已经用这个 proc 调用替换了它(因为我需要获取用户还没有看到的“建议”,所以它比上面的更复杂,基本上是“获取所有”;我还需要查询按 UserID 进行数据库,而 MVC 只有 User.Identity.Name):
var results = db.Database.SqlQuery<Advisory>("EXEC [ponzi].[uspUserAdvisories] {0}", User.Identity.Name).ToList();
ViewData["Advisories"] = results;
我知道 proc 返回所有结果(当我在 SQL Server 中运行它时),但在 MVC 中,当我将鼠标悬停在“结果”上时,会填写 AdvisoryCategoryID 但 AdvisoryCategory 为空。与其他两个查找相同。我认为这是因为 AdvisoryCategoryID 在我的 Advisory 模型中,但 AdvisoryCategory 来自 AdvisoryCategory 模型。
以下是咨询模型的相关部分:
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int AdvisoryId { get; set; }
public virtual int AdvisoryTypeID { get; set; }
public virtual AdvisoryTypes AdvisoryType { get; set; }
public virtual AdvisoryProviders AdvisoryProvider { get; set; }
public virtual int AdvisoryProviderID { get; set; }
public virtual AdvisoryCategories AdvisoryCategory { get; set; }
public virtual int AdvisoryCategoryID { get; set; }
如何让这三个查找字段显示 proc 返回的数据?谢谢。