Ejemplo n.º 1
0
 public T Get(Expression <Func <T, bool> > filter)
 {
     using (var context = new PortfolioContext())
     {
         return(context.Set <T>().SingleOrDefaultAsync(filter).Result);
     }
 }
Ejemplo n.º 2
0
 public void Update(T entity)
 {
     using (var context = new PortfolioContext())
     {
         var update = context.Entry(entity);
         update.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public void Insert(T entity)
 {
     using (var context = new PortfolioContext())
     {
         var insert = context.Entry(entity);
         insert.State = EntityState.Added;
         context.SaveChanges();
     }
 }
Ejemplo n.º 4
0
 public List <T> GetList(Expression <Func <T, bool> > filter = null)
 {
     using (var context = new PortfolioContext())
     {
         return(filter == null
             ? context.Set <T>().ToListAsync().Result
             : context.Set <T>().Where(filter).ToList());
     }
 }
Ejemplo n.º 5
0
 /*
  * public List<T> List()
  * {
  *  return _objectSet.ToList();
  * }
  * public List<T> List(Expression<Func<T, bool>> where)
  * {
  *  return _objectSet.Where(where).ToList();
  * }
  * public int Insert(T obj)
  * {
  *  _objectSet.Add(obj);
  *  return Save();
  * }
  *
  * public int Update(T obj)
  * {
  *  return Save();
  * }
  *
  * public int Delete(T obj)
  * {
  *  _objectSet.Remove(obj);
  *  return Save();
  * }
  *
  * public int Save()
  * {
  *  return db.SaveChanges();
  * }
  */
 public void Delete(T entity)
 {
     using (var context = new PortfolioContext())
     {
         var delete = context.Entry(entity);
         delete.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 protected static void CreatecoContext()
 {
     if (db == null)
     {
         lock (_locksyc)
         {
             if (db == null)
             {
                 db = new PortfolioContext();
             }
         }
     }
 }