コード例 #1
0
 public virtual void Update(params T[] items)
 {
     using (var context = new BibliotecaEntities())
     {
         DbSet <T> dbSet = context.Set <T>();
         foreach (T item in items)
         {
             dbSet.Add(item);
             foreach (DbEntityEntry <IEntity> entry in context.ChangeTracker.Entries <IEntity>())
             {
                 IEntity entity = entry.Entity;
                 entry.State = GetEntityState(entity.EntityState);
             }
         }
         context.SaveChanges();
     }
 }
コード例 #2
0
        public virtual IList <T> GetAll(params Expression <Func <T, object> >[] navigationProperties)
        {
            List <T> list;

            using (var context = new BibliotecaEntities())
            {
                IQueryable <T> dbQuery = context.Set <T>();

                //Apply eager loading
                foreach (Expression <Func <T, object> > navigationProperty in navigationProperties)
                {
                    dbQuery = dbQuery.Include <T, object>(navigationProperty);
                }

                list = dbQuery
                       .AsNoTracking()
                       .ToList <T>();
            }
            return(list);
        }
コード例 #3
0
        public virtual T GetSingle(Func <T, bool> where,
                                   params Expression <Func <T, object> >[] navigationProperties)
        {
            T item = null;

            using (var context = new BibliotecaEntities())
            {
                IQueryable <T> dbQuery = context.Set <T>();

                //Apply eager loading
                foreach (Expression <Func <T, object> > navigationProperty in navigationProperties)
                {
                    dbQuery = dbQuery.Include <T, object>(navigationProperty);
                }

                item = dbQuery
                       .AsNoTracking()
                       .FirstOrDefault(where);
            }
            return(item);
        }