Example #1
0
        /// <summary>
        /// 根据表达式删除指定类型的数据
        /// </summary>
        /// <typeparam name="T">指定类型</typeparam>
        /// <param name="cri">表达式</param>
        /// 前置条件
        /// 参数cri不允许为空
        public void Delete <T>(Criteria cri)
        {
            PreconditionAssert.IsNotNull(cri, ErrorMessages.NullReferenceException);
            ORMHelper.CheckEntityIsNotReadOnly(typeof(T), ErrorMessages.EntityReadOnly);

            DeleteCommandCreator dcc = new DeleteCommandCreator(_dbAccess);

            dcc.EntityType = typeof(T);
            dcc.criteria   = cri;
            dcc.deleteType = DeleteType.DeleteByCriteria;
            DbCommand dbCommand = dcc.GetDbCommand();

            _dbAccess.ExecCommand(dbCommand);
        }
Example #2
0
        /// <summary>
        /// 修改一个数据库中已有的对象,该对象的主键必须有值
        /// 该对象为空或主键为空或修改失败会抛出异常
        /// </summary>
        /// <param name="entity">需要修改的实体对象</param>
        /// 前置条件
        /// 参数entity不允许为空
        public void Modify(object entity)
        {
            //断言参入的参数为null或者空字符串(RErrorCode.NullReference - 0x00000001)
            PreconditionAssert.IsNotNull(entity, ErrorMessages.NullReferenceException);
            ORMHelper.EntityIsMappingDatabase(entity.GetType(), ErrorMessages.EntityMappingError);
            ORMHelper.CheckEntityIsNotReadOnly(entity.GetType(), ErrorMessages.EntityReadOnly);

            ModifyCommandCreator mcc = new ModifyCommandCreator(_dbAccess);

            mcc.Entity = entity;
            DbCommand dbCommand = mcc.GetDbCommand();

            _dbAccess.ExecCommand(dbCommand);
        }