Beispiel #1
0
 public List <T> GetAll <T>() where T : class
 {
     using (var context = new OnlineTestContext(_dbContextOptionBuilder.Options))
     {
         DbSet <T> dbSet      = context.Set <T>();
         var       entityList = dbSet.AsNoTracking().ToList();
         return(entityList);
     }
 }
Beispiel #2
0
 public T Get <T>(int id) where T : class
 {
     using (var context = new OnlineTestContext(_dbContextOptionBuilder.Options))
     {
         DbSet <T> dbSet  = context.Set <T>();
         var       entity = dbSet.Find(id);
         return(entity);
     }
 }
Beispiel #3
0
 public T Delete <T>(T entity) where T : class
 {
     using (var context = new OnlineTestContext(_dbContextOptionBuilder.Options))
     {
         DbSet <T> dbSet = context.Set <T>();
         dbSet.Remove(entity);
         context.SaveChanges();
         return(entity);
     }
 }
Beispiel #4
0
 public bool AddAll <T>(List <T> entityList) where T : class
 {
     using (var context = new OnlineTestContext(_dbContextOptionBuilder.Options))
     {
         try
         {
             DbSet <T> dbSet = context.Set <T>();
             foreach (var entity in entityList)
             {
                 dbSet.Add(entity);
             }
             context.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             return(false);
         }
     }
 }