Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Course : Entity
- {
- public string Identification { get; set; }
- public double Price { get; set; }
- public bool Active { get; set; }
- public Guid CourseTypeId { get; set; }
- public virtual CourseType CourseType { get; set; }
- public Guid InstructorId { get; set; }
- public virtual Instructor Instructor { get; set; }
- public ICollection<OrderDetail> OrderDetails { get; set; }
- public ValidationResult ValidationResult { get; set; }
- public bool IsValid()
- {
- ValidationResult = new CourseIsConsistentValidation().Validate(this);
- return ValidationResult.IsValid;
- }
- }
- public class CourseType : Entity
- {
- public string Identification { get; set; }
- public bool Active { get; set; }
- public virtual ICollection<Course> Courses { get; set; }
- public ValidationResult ValidationResult { get; set; }
- public bool IsValid()
- {
- ValidationResult = new CourseTypeIsConsistentValidation().Validate(this);
- return ValidationResult.IsValid;
- }
- }
- public class Instructor : Entity
- {
- public string Identification { get; set; }
- public DateTime BirthDate { get; set; }
- public string Email { get; set; }
- public int LicenseNumber { get; set; }
- public bool Active { get; set; }
- public ICollection<Course> Courses { get; set; }
- public ValidationResult ValidationResult { get; set; }
- public bool IsValid()
- {
- ValidationResult = new InstructorIsConsistentValidation().Validate(this);
- return ValidationResult.IsValid;
- }
- }
- public IEnumerable<Course> GetActive()
- {
- query.AppendLine("SELECT c.Id,");
- query.AppendLine(" c.Identification,");
- query.AppendLine(" c.Price,");
- query.AppendLine(" c.Active,");
- query.AppendLine(" c.CourseTypeId,");
- query.AppendLine(" c.InstructorId,");
- query.AppendLine(" ct.Identification as CourseType,");
- query.AppendLine(" i.Identification as Instructor");
- query.AppendLine(" FROM Courses c");
- query.AppendLine(" INNER JOIN CourseTypes ct");
- query.AppendLine(" ON ct.Id = c.CourseTypeId");
- query.AppendLine(" INNER JOIN Instructors i");
- query.AppendLine(" ON i.Id = c.InstructorId");
- query.AppendLine(" WHERE c.Active = 1");
- return Context.Database.SqlQuery<Course>(query.ToString()).ToList();
- }
- Context.Database.Connection.Query (Course, CourseType, Instructor)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement