【发布时间】:2018-08-26 07:13:14
【问题描述】:
我有一个 ViewModel:
public class ApplicationContentViewModel
{
public BPMSPARS.Models.MySql.application application {get; set;}
public BPMSPARS.Models.MySql.content content { get; set; }
public BPMSPARS.Models.MySql.app_delegation app_delegation { get; set; }
}
另一方面,我想在 View 中创建一个包含此输出的列表:
@foreach (var item in Model)
{
i++;
<tr>
<td>@i</td>
<th>
@item.content.CON_VALUE
//where CATEGORY="TASK"
</th>
<th>
@item.content.CON_VALUE
//where CATEGORY="PRO_TITLE"
</th>
<th>@item.application.APP_CREATE_DATE</th>
<th>@User.Identity.Name.Split('-')[0]</th>
</tr>
}
实际上我想在两列中显示一个字段,条件不同( @item.content.CON_VALUE)。
首先,我使用这个查询,但它不能返回第一个@item.content.CON_VALUE,我不能为一个字段应用两个条件(在两列中)。
public ActionResult ProcessList()
{
var db1 = new wf_workflowEntities();
ApplicationContentViewModel APVM = new ApplicationContentViewModel();
var ViewModel = (from APP in db1.application
join app_del in db1.app_delegation on APP.APP_UID equals app_del.APP_UID
join Con in db1.content on APP.PRO_UID equals Con.CON_ID
where Con.CON_ID == APP.PRO_UID && app_del.APP_UID == APP.APP_UID && Con.CON_CATEGORY == "PRO_TITLE"
select new ApplicationContentViewModel
{
app_delegation = app_del,
application = APP,
content = Con,
}).AsEnumerable();
return View(ViewModel);
}
你知道一个合适的解决方案吗?
【问题讨论】:
标签: asp.net-mvc inner-join viewmodel ef-database-first nested-select