public static DisciplineCollection ConfiguredDisciplines(string className, short year) { using (HonglornDb db = new HonglornDb()) { DisciplineCollection collection = (from c in db.DisciplineCollection where c.ClassName == className && c.Year == year select c).SingleOrDefault(); if (collection != null) { // Pre-load properties; otherwise they won't be available after the context is disposed. IEnumerable <Expression <Func <DisciplineCollection, Discipline> > > references = new Expression <Func <DisciplineCollection, Discipline> >[] { c => c.MaleSprint, c => c.MaleJump, c => c.MaleThrow, c => c.MaleMiddleDistance, c => c.FemaleSprint, c => c.FemaleJump, c => c.FemaleThrow, c => c.FemaleMiddleDistance }; foreach (Expression <Func <DisciplineCollection, Discipline> > reference in references) { db.Entry(collection).Reference(reference).Load(); } } return(collection); } }
public static void DeleteCompetitionDisciplineByPKey(Guid pKey) { try { using (HonglornDb db = new HonglornDb()) { CompetitionDiscipline discipline = new CompetitionDiscipline { PKey = pKey }; db.Entry(discipline).State = EntityState.Deleted; db.SaveChanges(); } } catch (Exception ex) { throw new ArgumentException($"A {nameof(CompetitionDiscipline)} with PKey {pKey} does not exist in the database.", ex); } }