public static void Insert(Branch branch) { using (PracticeContext context = new PracticeContext()) { Repository <Branch> repository = new Repository <Branch>(context); repository.Insert(branch); } }
public static void Insert(Student student) { using (PracticeContext context = new PracticeContext()) { Repository <Student> repository = new Repository <Student>(context); repository.Insert(student); } }
private async static Task <TResult> ExecuteAsync <T, TResult>(Func <Repository <T>, Task <TResult> > func) where T : class { using (PracticeContext context = new PracticeContext()) { try { return(await func(new Repository <T>(context))); } catch (Exception ex) { Console.WriteLine(ex); throw new Exception("Error Occured."); } } }
private static void Execute <T>(Action <Repository <T> > action) where T : class { using (PracticeContext context = new PracticeContext()) { try { action(new Repository <T>(context)); } catch (SqlException ex) { Console.WriteLine(ex); throw new Exception("Error Occured."); } } }
public Repository(PracticeContext context) { this.context = context; }