Пример #1
0
        /// <summary>
        /// 新增一个实体对象到数据库中
        /// </summary>
        /// <param name="entity">需要保存的实体对象</param>
        /// 前置条件:
        /// 1.参数entity不允许为空
        public void Add(object entity)
        {
            //断言参入的参数为null或者空字符串(RErrorCode.NullReference - 0x00000001)
            PreconditionAssert.IsNotNull(entity, ErrorMessages.NullReferenceException);
            ORMHelper.EntityIsMappingDatabase(entity.GetType(), ErrorMessages.EntityMappingError);
            ORMHelper.CheckEntityIsNotReadOnly(entity.GetType(), ErrorMessages.EntityReadOnly);

            InsertCommandCreator icc = new InsertCommandCreator(_dbAccess);

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

            _dbAccess.ExecCommand(dbCommand);
        }