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

            DeleteCommandCreator dcc = new DeleteCommandCreator(_dbAccess);

            dcc.deleteType = DeleteType.Delete;
            dcc.Entity     = entity;
            DbCommand dbCommand = dcc.GetDbCommand();

            _dbAccess.ExecCommand(dbCommand);
        }