Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. public class Course : Entity
  2. {
  3. public string Identification { get; set; }
  4. public double Price { get; set; }
  5. public bool Active { get; set; }
  6.  
  7. public Guid CourseTypeId { get; set; }
  8. public virtual CourseType CourseType { get; set; }
  9.  
  10. public Guid InstructorId { get; set; }
  11. public virtual Instructor Instructor { get; set; }
  12.  
  13. public ICollection<OrderDetail> OrderDetails { get; set; }
  14.  
  15. public ValidationResult ValidationResult { get; set; }
  16.  
  17. public bool IsValid()
  18. {
  19. ValidationResult = new CourseIsConsistentValidation().Validate(this);
  20.  
  21. return ValidationResult.IsValid;
  22. }
  23. }
  24.  
  25. public class CourseType : Entity
  26. {
  27. public string Identification { get; set; }
  28. public bool Active { get; set; }
  29.  
  30. public virtual ICollection<Course> Courses { get; set; }
  31.  
  32. public ValidationResult ValidationResult { get; set; }
  33.  
  34. public bool IsValid()
  35. {
  36. ValidationResult = new CourseTypeIsConsistentValidation().Validate(this);
  37.  
  38. return ValidationResult.IsValid;
  39. }
  40. }
  41.  
  42. public class Instructor : Entity
  43. {
  44. public string Identification { get; set; }
  45. public DateTime BirthDate { get; set; }
  46. public string Email { get; set; }
  47. public int LicenseNumber { get; set; }
  48. public bool Active { get; set; }
  49.  
  50. public ICollection<Course> Courses { get; set; }
  51.  
  52. public ValidationResult ValidationResult { get; set; }
  53.  
  54. public bool IsValid()
  55. {
  56. ValidationResult = new InstructorIsConsistentValidation().Validate(this);
  57.  
  58. return ValidationResult.IsValid;
  59. }
  60. }
  61.  
  62. public IEnumerable<Course> GetActive()
  63. {
  64. query.AppendLine("SELECT c.Id,");
  65. query.AppendLine(" c.Identification,");
  66. query.AppendLine(" c.Price,");
  67. query.AppendLine(" c.Active,");
  68. query.AppendLine(" c.CourseTypeId,");
  69. query.AppendLine(" c.InstructorId,");
  70. query.AppendLine(" ct.Identification as CourseType,");
  71. query.AppendLine(" i.Identification as Instructor");
  72. query.AppendLine(" FROM Courses c");
  73. query.AppendLine(" INNER JOIN CourseTypes ct");
  74. query.AppendLine(" ON ct.Id = c.CourseTypeId");
  75. query.AppendLine(" INNER JOIN Instructors i");
  76. query.AppendLine(" ON i.Id = c.InstructorId");
  77. query.AppendLine(" WHERE c.Active = 1");
  78.  
  79. return Context.Database.SqlQuery<Course>(query.ToString()).ToList();
  80. }
  81.  
  82. Context.Database.Connection.Query (Course, CourseType, Instructor)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement