Пример #1
0
        //delete
        public static void Delete <BO, EO>(BO obj, DbContext context, DbSet <EO> dbSet, List <string> dbColumns = null, bool bCommitOnChange = true)
            where BO : new()
            where EO : class, new()
        {
            bool validateOnSaveEnabled = context.Configuration.ValidateOnSaveEnabled;
            EO   entityObj             = new EO();

            try {
                if (dbColumns == null)
                {
                    entityObj = BusinessLayerUtils.PopulateEntity <EO, BO>(obj);
                }
                else
                {
                    entityObj = BusinessLayerUtils.PopulateEntity <EO, BO>(obj, dbColumns);
                }

                context.Configuration.ValidateOnSaveEnabled = false;
                context.Entry <EO>(entityObj).State         = EntityState.Deleted;
                if (bCommitOnChange)
                {
                    context.SaveChanges();
                }
            } catch (Exception ex) { ThrowException <BO>(context, "Delete()", ex); } finally { context.Configuration.ValidateOnSaveEnabled = validateOnSaveEnabled; }
        }
Пример #2
0
        //Update
        public static void Update <BO, EO>(BO obj, DbContext context, DbSet <EO> dbSet, List <string> dbColumns = null, bool bCommitOnChange = true)
            where BO : new()
            where EO : class, new()
        {
            EO entityObj = new EO();

            try {
                if (dbColumns == null)
                {
                    entityObj = BusinessLayerUtils.PopulateEntity <EO, BO>(obj);
                }
                else
                {
                    entityObj = BusinessLayerUtils.PopulateEntity <EO, BO>(obj, dbColumns);
                }
                context.Entry <EO>(entityObj).State = EntityState.Modified;
                if (bCommitOnChange)
                {
                    context.SaveChanges();
                }
            } catch (Exception ex) { ThrowException <BO>(context, "Update()", ex); }
        }
Пример #3
0
        //Insert
        public static EO Insert <BO, EO>(BO obj, DbContext context, DbSet <EO> dbSet, List <string> dbColumns = null, bool bCommitOnChange = true)
            where BO : new()
            where EO : class, new()
        {
            EO entityObj = new EO();

            try {
                if (dbColumns == null)
                {
                    entityObj = BusinessLayerUtils.PopulateEntity <EO, BO>(obj);
                }
                else
                {
                    entityObj = BusinessLayerUtils.PopulateEntity <EO, BO>(obj, dbColumns);
                }
                dbSet.Add(entityObj);
                if (bCommitOnChange)
                {
                    context.SaveChanges();
                }
            } catch (Exception ex) { ThrowException <BO>(context, "Insert()", ex); }
            return(entityObj);
        }
 protected static List <I> GetCollection(IEnumerable <E> entitySet, List <string> DBColumns = null)
 {
     return(BusinessLayerUtils.BuildCollectionFromEntitySet <I, E>(entitySet, DBColumns));
 }
 protected static I GetOneObject(E entity)
 {
     return(BusinessLayerUtils.PopulateObject <I, E>(entity));
 }
Пример #6
0
 protected static List <I> GetCollection(IEnumerable <E> entitySet)
 {
     return(BusinessLayerUtils.BuildCollectionFromEntitySet <I, E>(entitySet));
 }