示例#1
0
 public bool Add(T item)
 {
     try
     {
         db.Entry(item).State = EntityState.Added;
         db.SaveChanges();
         return(true);
     }
     catch
     {
         throw;
     }
 }
示例#2
0
 public bool Update(T obj)
 {
     using (var d = new PlasticFactoryEntities())
         try
         {
             DbSet dSet = d.Set <T>();
             dSet.Attach(obj);
             d.Entry(obj).State = EntityState.Modified;
             d.SaveChanges();
             return(true);
         }
         catch
         {
             throw;
         }
 }
示例#3
0
 public bool Delete(T item)
 {
     try
     {
         if (db.Entry(item).State == EntityState.Detached)
         {
             dbSet.Attach(item);
         }
         dbSet.Remove(item);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }