日期:2014-05-20 浏览次数:20983 次
public class Tasks { public int TaskId { get; set; } public string TaskName { get; set; } public DateTime StartDate { get; set; } public string StartTime { get; set; } public string EndTime { get; set; } public DateTime EndDate { get; set; } public virtual Schedule Schedule { get; set; } public virtual ICollection<Schedule> Schedules { get; set; } public virtual ICollection<Tag> Tags { get; set; } public virtual UserInfo UserInfo { get; set; } } public class Schedule { public int ScheduleId { get; set; } public int TaskId { get; set; } public DateTime LastExecutionTime { get; set; } public DateTime NextExecutionTime { get; set; } public virtual Tasks Tasks { get; set; } } //Tasks modelBuilder.Entity<Tasks>().HasKey(o => o.TaskId).ToTable("Tasks"); modelBuilder.Entity<Tasks>().Property(o => o.TaskId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); modelBuilder.Entity<Tasks>().Property(o => o.StartDate).IsOptional().HasColumnType("datetime2"); modelBuilder.Entity<Tasks>().Property(o => o.StartTime).IsRequired(); modelBuilder.Entity<Tasks>().Property(o => o.EndTime).IsRequired(); modelBuilder.Entity<Tasks>().Property(o => o.EndDate).IsOptional().HasColumnType("datetime2"); modelBuilder.Entity<Tasks>().Property(o => o.Desc).IsOptional().HasMaxLength(512); modelBuilder.Entity<Tasks>().Ignore(o => o.Schedule); // Schedule modelBuilder.Entity<Schedule>().HasKey(o => o.ScheduleId).ToTable("Schedule"); modelBuilder.Entity<Schedule>().Property(o => o.ScheduleId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); modelBuilder.Entity<Schedule>().Property(o => o.ScheduleTypeId).IsRequired(); modelBuilder.Entity<Schedule>().Property(o => o.LastExecutionTime).IsOptional().HasColumnType("datetime2"); modelBuilder.Entity<Schedule>().Property(o => o.NextExecutionTime).IsOptional().HasColumnType("datetime2"); modelBuilder.Entity<Schedule>().HasRequired(o => o.Tasks).WithMany(o => o.Schedules).HasForeignKey(f => f.TaskId);
public virtual IEnumerable<T> GetMany( Expression<Func<T, bool>> filter = null, Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null, string includeProperties = "") { IQueryable<T> query = dbSet; if (filter != null) { query = query.Where(filter); } foreach (var includeProperty in includeProperties.Split (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { query = query.Include(includeProperty); } if (orderBy != null) { return orderBy(query).ToList(); } else { return query.ToList(); } } return taskRepository.GetMany( filter: k => k.UserId == userId || k.Schedule.NextExecutionTime < nextExecutionTime, orderBy: o => o.OrderBy(k => k.TaskId), includeProperties: "Schedules,Tags");