我采用code frist方式:
Course表
Grade表
GradeToCourse表
Course:
public class Course
{
public int ID { get; set; }
public string Name { get; set; }
public int? Sort { get; set; }
public bool? IsShow { get; set; }
public DateTime? UpdateTime { get; set; }
public virtual IList<Grade> Grades { get; set; }
}
Grade:
public class Grade
{
public int ID { get; set; }
public int SchoolID { get; set; }
public string GradeName { get; set; }
public int? Sort { get; set; }
public bool? IsShow { get; set; }
public DateTime? UpdateTime { get; set; }
public virtual IList<Class> Classes { get; set; }
public virtual School School { get; set; }
public virtual IList<Student> Students { get; set; }
public virtual IList<Course> Courses { get; set; }
}
public CourseMap()
{
// Primary Key
this.HasKey(t => t.ID); // Properties
this.Property(t => t.ID)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
this.Property(t => t.Name)
.HasMaxLength(20);
// Table & Column Mappings
this.ToTable("Course");
this.Property(t => t.ID).HasColumnName("ID");
this.Property(t => t.Name).HasColumnName("Name");
this.Property(t => t.Sort).HasColumnName("Sort");
this.Property(t => t.IsShow).HasColumnName("IsShow");
this.Property(t => t.UpdateTime).HasColumnName("UpdateTime"); // Relationships
this.HasMany(t => t.Grades)
.WithMany(t => t.Courses)
.Map(m =>
{
m.ToTable("GradeToCourse");
m.MapLeftKey("CourseID");
m.MapRightKey("GradeID");
});
}
我现在想查询GradeToCourse表中的内容,然后分页,如何查询啊
Course表
Grade表
GradeToCourse表
Course:
public class Course
{
public int ID { get; set; }
public string Name { get; set; }
public int? Sort { get; set; }
public bool? IsShow { get; set; }
public DateTime? UpdateTime { get; set; }
public virtual IList<Grade> Grades { get; set; }
}
Grade:
public class Grade
{
public int ID { get; set; }
public int SchoolID { get; set; }
public string GradeName { get; set; }
public int? Sort { get; set; }
public bool? IsShow { get; set; }
public DateTime? UpdateTime { get; set; }
public virtual IList<Class> Classes { get; set; }
public virtual School School { get; set; }
public virtual IList<Student> Students { get; set; }
public virtual IList<Course> Courses { get; set; }
}
public CourseMap()
{
// Primary Key
this.HasKey(t => t.ID); // Properties
this.Property(t => t.ID)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
this.Property(t => t.Name)
.HasMaxLength(20);
// Table & Column Mappings
this.ToTable("Course");
this.Property(t => t.ID).HasColumnName("ID");
this.Property(t => t.Name).HasColumnName("Name");
this.Property(t => t.Sort).HasColumnName("Sort");
this.Property(t => t.IsShow).HasColumnName("IsShow");
this.Property(t => t.UpdateTime).HasColumnName("UpdateTime"); // Relationships
this.HasMany(t => t.Grades)
.WithMany(t => t.Courses)
.Map(m =>
{
m.ToTable("GradeToCourse");
m.MapLeftKey("CourseID");
m.MapRightKey("GradeID");
});
}
我现在想查询GradeToCourse表中的内容,然后分页,如何查询啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货