コード例 #1
0
        public static List <T> GetList <T>(Expression <Func <T, bool> > expression)  where T : class
        {
            List <T> DataList = new List <T>();

            try
            {
                using (UniWebEntities uniWebEntities = new UniWebEntities())
                {
                    DataList = uniWebEntities.Set <T>().Where(expression).ToList();
                }
            }catch (Exception ex)
            {
            }
            return(DataList);
        }
コード例 #2
0
        public static T GetData <T>(Expression <Func <T, bool> > expression) where T : class
        {
            T data = null;

            try
            {
                using (UniWebEntities uniWebEntities = new UniWebEntities())
                {
                    data = uniWebEntities.Set <T>().Where(expression).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
            }
            return(data);
        }
コード例 #3
0
        public static bool AddData <T>(List <T> listData) where T : class
        {
            bool IsSuccess = false;

            try
            {
                using (UniWebEntities uniWebEntities = new UniWebEntities())
                {
                    uniWebEntities.Set <T>().AddRange(listData);
                    uniWebEntities.SaveChanges();
                    return(true);
                }
            }catch (Exception ex)
            {
            }
            return(IsSuccess);
        }
コード例 #4
0
        public static bool Update <T>(T data) where T : class
        {
            bool IsSuccess = false;

            try
            {
                using (UniWebEntities uniWebEntities = new UniWebEntities())
                {
                    uniWebEntities.Entry <T>(data).State = System.Data.Entity.EntityState.Modified;
                    uniWebEntities.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
            }
            return(IsSuccess);
        }
コード例 #5
0
        public static bool Delete <T>(T data) where T : class
        {
            bool IsSuccess = false;

            try
            {
                using (UniWebEntities uniWebEntities = new UniWebEntities())
                {
                    uniWebEntities.Set <T>().Remove(data);
                    uniWebEntities.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
            }
            return(IsSuccess);
        }
コード例 #6
0
        public static bool Update <T>(Expression <Func <T, bool> > expression) where T : class
        {
            bool IsSuccess = false;

            try
            {
                using (UniWebEntities uniWebEntities = new UniWebEntities())
                {
                    T data = uniWebEntities.Set <T>().Where(expression).ToList().FirstOrDefault();
                    uniWebEntities.Entry <T>(data).State = System.Data.Entity.EntityState.Modified;
                    uniWebEntities.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
            }
            return(IsSuccess);
        }
コード例 #7
0
        public static bool Delete <T>(Expression <Func <T, bool> > expression) where T : class
        {
            bool IsSuccess = false;

            try
            {
                using (UniWebEntities uniWebEntities = new UniWebEntities())
                {
                    T data = uniWebEntities.Set <T>().Where(expression).ToList().FirstOrDefault();
                    uniWebEntities.Set <T>().Remove(data);
                    uniWebEntities.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
            }
            return(IsSuccess);
        }
コード例 #8
0
        public static bool DeleteRange <T>(Expression <Func <T, bool> > expression) where T : class
        {
            bool IsSuccess = false;

            try
            {
                using (UniWebEntities uniWebEntities = new UniWebEntities())
                {
                    // uniWebEntities.Entry<T>(expression).State = System.Data.Entity.EntityState.Deleted ;
                    List <T> removeDataList = uniWebEntities.Set <T>().Where(expression).ToList();
                    uniWebEntities.Set <T>().RemoveRange(removeDataList);
                    uniWebEntities.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
            }
            return(IsSuccess);
        }