0

我有这些类,我正在使用存储库模式并试图让 IEnumerable 包含 WorkOrderDetail。我是 MVC 和实体框架的新手,我不知道如何包含 WorkOrderDetails。

public IEnumerable<Schedule> GetFuture()
        {
            string tZone = "Pacific Standard Time";

            DateTime today = Today(tZone);

            var schedule = context.Schedules
                .Where(s => s.Date >= today).ToList();            

            return schedule;
        }

public abstract class Entity
    {
        public int Id { get; set; }
    }

 public class Schedule : Entity
    {
        public DateTime Date { get; set; }

        public bool Free { get; set; }

        public int WorkOrderId { get; set; }
        public virtual WorkOrder WorkOrder { get; set; }          
    }

 public class WorkOrder : Entity
    {

        public string Name { get; set; }
        public string Type { get; set; }

        public virtual ICollection<WorkOrderDetail> WorkOrderDetails { get; set; }
     }
public class WorkOrderDetail : Entity
    {
       public string Job { get; set; }
       public bool Finished { get; set; }
    }
4

1 回答 1

1

改变这个:

var schedule = context.Schedules.Where(s => s.Date >= today).ToList();    

至:

var schedule = context.Schedules.Include("WorkOrder.WorkOrderDetail").Where(s => s.Date >= today).ToList();
于 2012-06-19T01:51:33.147 回答