/// <summary> /// Creates a <see cref="University"/> instance in the database /// </summary> /// <param name="university"> /// The <see cref="University"/> instance to persist to the database /// </param> public void Create(University university) { using (var context = new DnugContext(this.connectionString)) { context.Universities.Add(university); context.SaveChanges(); } }
/// <summary> /// Deletes the <see cref="University"/> instance with the specified <see cref="id"/> /// </summary> /// <param name="id"> /// The id of the <see cref="University"/> to delete /// </param> public void Delete(Guid id) { using (var context = new DnugContext(this.connectionString)) { University university = (from u in context.Universities where u.Id == id select u).First(); context.Universities.Remove(university); context.SaveChanges(); } }
/// <summary> /// Queries the repository to establish how many <see cref="University"/> instances contain a student registered with a given forename /// </summary> /// <param name="forename"> /// The forename to search for /// </param> /// <returns> /// The count of <see cref="University"/> instances containing a <see cref="Student"/> with the matching forename /// </returns> public int Query(string forename) { using (var context = new DnugContext(this.connectionString)) { return (from university in context.Universities from faculty in university.Faculties from course in faculty.CoursesOffered from student in course.RegisteredStudents where student.Forename.Equals(forename) select student).Count(); } }
/// <summary> /// Updates a scalar property on the <see cref="University"/> instance associated to the <see cref="id"/> parameter /// </summary> /// <param name="id"> /// The id of the <see cref="University"/> to load /// </param> /// <param name="name"> /// The new name to apply to the <see cref="University"/> /// </param> public void Update(Guid id, string name) { using (var context = new DnugContext(this.connectionString)) { University university = (from u in context.Universities where u.Id == id select u).First(); university.Name = name; context.SaveChanges(); } }
/// <summary> /// Retrieves an instance of <see cref="University"/> for the given id /// </summary> /// <param name="id"> /// The id of the <see cref="University"/> to load /// </param> /// <returns> /// A <see cref="University"/> instance matching the requested id /// </returns> public University Retrieve(Guid id) { using (var context = new DnugContext(this.connectionString)) { return (from u in context.Universities .Include("Location") .Include("Faculties") .Include("Faculties.Address") .Include("Faculties.CoursesOffered") .Include("Faculties.CoursesOffered.RegisteredStudents") .Include("Faculties.CoursesOffered.RegisteredStudents.Address") where u.Id == id select u).First(); } }