コード例 #1
0
        public IEnumerable <TEntity> GetAll()
        {
            IEnumerable <TEntity> result = null;

            try
            {
                using (var db = new WebFormLoginContext())
                {
                    result = db.Set <TEntity>().Where(i => !i.IsDeleted).ToList();
                }
            }
            catch (Exception)
            {
            }
            return(result ?? Enumerable.Empty <TEntity>());
        }
コード例 #2
0
        public IEnumerable <TEntity> FindBy(Expression <Func <TEntity, bool> > predicate)
        {
            IEnumerable <TEntity> result = null;

            try
            {
                using (var db = new WebFormLoginContext())
                {
                    result = db.Set <TEntity>().Where(i => !i.IsDeleted).Where(predicate).ToList();
                }
            }
            catch (Exception ex)
            {
            }
            return(result ?? Enumerable.Empty <TEntity>());
        }
コード例 #3
0
        public TEntity SingleBy(Expression <Func <TEntity, bool> > predicate)
        {
            TEntity entity = null;

            try
            {
                using (var db = new WebFormLoginContext())
                {
                    entity = db.Set <TEntity>().Where(i => !i.IsDeleted).FirstOrDefault(predicate);
                }
            }
            catch (Exception ex)
            {
            }

            return(entity);
        }
コード例 #4
0
        public TEntity Insert(TEntity dto)
        {
            TEntity entity = null;

            try
            {
                using (var db = new WebFormLoginContext())
                {
                    entity = db.Set <TEntity>().Add(dto);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
            }
            return(entity);
        }
コード例 #5
0
        public TEntity GetById(Guid id)
        {
            TEntity entity = null;

            try
            {
                using (var db = new WebFormLoginContext())
                {
                    entity = db.Set <TEntity>().Find(id);
                }
            }
            catch (Exception ex)
            {
            }

            return(entity);
        }
コード例 #6
0
        public TEntity Update(TEntity dto)
        {
            TEntity entity = null;

            try
            {
                using (var db = new WebFormLoginContext())
                {
                    entity = db.Set <TEntity>().Find(dto.Id);
                    if (entity != null)
                    {
                        db.Entry(entity).CurrentValues.SetValues(dto);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                entity = null;
            }
            return(entity);
        }