예제 #1
0
 public BindableCollection <T> GetList <T>() where T : class
 {
     using (QLTVEntities db = new QLTVEntities())
     {
         return(new BindableCollection <T>(db.Set <T>().ToList()));
     }
 }
예제 #2
0
 public T GetItem <T>(Expression <Func <T, bool> > currentEntityFilter) where T : class
 {
     using (QLTVEntities db = new QLTVEntities())
     {
         var current = db.Set <T>().FirstOrDefault(currentEntityFilter);
         return(current);
     }
 }
예제 #3
0
 public T GetItemInclude <T>(Expression <Func <T, object> >[] includes) where T : class
 {
     using (QLTVEntities db = new QLTVEntities())
     {
         var query = db.Set <T>().AsQueryable();
         if (includes != null)
         {
             query = includes.Aggregate(query, (current, include) => current.Include(include));
         }
         return(query.FirstOrDefault());
     }
 }
예제 #4
0
 public bool Delete <T>(Expression <Func <T, bool> > currentEntityFilter) where T : class
 {
     using (QLTVEntities db = new QLTVEntities())
     {
         try
         {
             var current = db.Set <T>().FirstOrDefault(currentEntityFilter);
             if (current is null)
             {
                 return(false);
             }
             db.Set <T>().Remove(current);
             db.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             MessageBox.Show(e.Message);
             return(false);
         }
     }
 }
예제 #5
0
 public bool Create <T>(T dto) where T : class
 {
     using (QLTVEntities db = new QLTVEntities())
     {
         try
         {
             db.Set <T>().Add(dto);
             db.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             MessageBox.Show(e.Message);
             return(false);
         }
     }
 }
예제 #6
0
 public bool Update <T>(T dto, Expression <Func <T, bool> > currentEntityFilter) where T : class
 {
     using (QLTVEntities db = new QLTVEntities())
     {
         try
         {
             var current = db.Set <T>().FirstOrDefault(currentEntityFilter);
             if (current is null)
             {
                 return(false);
             }
             db.Entry(current).CurrentValues.SetValues(dto);
             db.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             return(false);
         }
     }
 }