private static void SetPersistenceMethod <T>(BuilderSettings builderSettings) where T : class
    {
        builderSettings.SetCreatePersistenceMethod <T>((item) =>
        {
            using (var db = new ProductsDbContext())
            {
                db.Set <T>().Attach(item);
                db.Set <T>().Add(item);
                db.SaveChanges();
            }
        });

        builderSettings.SetCreatePersistenceMethod <IList <T> >((items) =>
        {
            using (var db = new ProductsDbContext())
            {
                foreach (var item in items)
                {
                    db.Set <T>().Attach(item);
                    db.Set <T>().Add(item);
                }
                db.SaveChanges();
            }
        });

        builderSettings.SetUpdatePersistenceMethod <T>(item =>
        {
            using (var db = new ProductsDbContext())
            {
                db.Set <T>().Attach(item);
                db.Entry(item).State = EntityState.Modified;
                db.SaveChanges();
            }
        });

        builderSettings.SetUpdatePersistenceMethod <IList <T> >((items) =>
        {
            using (var db = new ProductsDbContext())
            {
                foreach (var item in items)
                {
                    db.Set <T>().Attach(item);
                    db.Entry(item).State = EntityState.Modified;
                    db.Set <T>().Add(item);
                }
                db.SaveChanges();
            }
        });
    }
Example #2
0
 public void GetList <T>() where T : class
 {
     try
     {
         var list = _context.Set <T>();
     }
     catch (Exception)
     {
         throw;
     }
 }
        public void Delete(T entity)
        {
            T existing = _context.Set <T>().Find(entity);

            if (existing != null)
            {
                _context.Set <T>().Remove(existing);
                _context.SaveChanges();
            }
        }
Example #4
0
 public IQueryable <T> Query <T>() where T : class
 {
     return(_dataContext.Set <T>().AsQueryable());
 }