如何解决ASP.NET MVC LINQ:在 Action 中加入另一个模型
我想将另一个模型加入我当前的 MVC 操作中,以便能够读取视图中的外键。我想将“ProductiveUnit”模型加入到下面的操作中,其中 ProductiveUnit 被加入到 ProdUnitID 的 EventTaskviewmodel 上。 ProductiveUnit 的所有字段都可以在视图中使用,或者只有“ProdUnitNo”,都没有关系。使用下面的 LINQ 请告知如何在 EventGantt_Read 操作中完成此操作:
public ActionResult EventGantt_Read([DataSourceRequest] DataSourceRequest request,int[] PUID)
{
var data = (from e in db.Events.Where(t => PUID.Contains((int)t.ProductiveUnitID))
join p in db.ProductiveUnits on e.ProductiveUnitID equals p.ProdUnitID
select new { EventID = e.EventID,EventDescription = e.EventDescription,ProductiveUnitID = e.ProductiveUnitID,ActualStart = e.ActualStart,ActualEnd = e.ActualEnd,ParentEventID = e.ParentEventID,ActivityCodeID = e.ActivityCodeID,ProdUnitNo = p.ProdUnitNo }).ToList()
.Select(eventList => new EventTaskviewmodel(eventList))
.AsQueryable();
return Json(data.ToDataSourceResult(request));
}
.Select(eventList => new EventTaskviewmodel(eventList))
在 eventList
上说无法从“
我的 EventTaskviewmodel:
namespace EMS.Models
{
public class EventTaskviewmodel : IGanttTask
{
public EventTaskviewmodel()
{
}
public EventTaskviewmodel(Event eventList)
{
ID = eventList.EventID;
Title = eventList.EventDescription;
ProductiveUnitID = eventList.ProductiveUnitID;
Start = DateTime.SpecifyKind(eventList.ActualStart,DateTimeKind.Local);
End = DateTime.SpecifyKind(eventList.ActualEnd,DateTimeKind.Local);
EventStatusID = eventList.EventStatusID;
ParentID = eventList.ParentEventID;
ActivityCodeID = eventList.ActivityCodeID;
}
public int ID { get; set; }
public int? ParentID { get; set; }
public string Title { get; set; }
public int? ProductiveUnitID { get; set; }
public string ActivityCodeID { get; set; }
// public virtual ICollection<ActivityCode> ActivityCode { get; set; }
// public ActivityCode Activity { get; set; }
public string EventStatusID { get; set; }
private DateTime start;
public DateTime Start
{
get
{
return start;
}
set
{
start = value; //.ToUniversalTime();
}
}
private DateTime end;
public DateTime End
{
get
{
return end;
}
set
{
end = value; //.ToUniversalTime();
}
}
public bool Summary { get; set; }
public bool Expanded { get; set; }
public decimal PercentComplete { get; set; }
public int OrderId { get; set; }
public Event ToEntity()
{
return new Event
{
EventID = ID,ParentEventID = ParentID,EventDescription = Title,ProductiveUnitID = ProductiveUnitID,ActivityCodeID = ActivityCodeID,EventStatusID = EventStatusID,ActualStart = Start,ActualEnd = End,GanttSummary = Summary,GanttExpanded = Expanded,GanttPercentComplete = PercentComplete,GanttOrderID = OrderId
};
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。