public static void Verify(DbContext dbContext, IEntity entity, int dmlType) { if (entity == null) { return; } Type entityType = entity.GetType(); if (dmlType != GlobalConstants.DML_OPERATION_INSERT && dmlType != GlobalConstants.DML_OPERATION_UPDATE && dmlType != GlobalConstants.DML_OPERATION_DELETE) { throw new BusinessException(GlobalConstants.EXCEPTION_CODE_PARAMETER_INVALID, "错误的dmlType"); } if (dmlType == GlobalConstants.DML_OPERATION_INSERT) { if (dbContext.Find(entityType, entity.RecordId) != null) { throw new BusinessException(GlobalConstants.EXCEPTION_CODE_DATA_ALREADY_EXISTS, $"Id为{entity.RecordId}的{entityType}数据已存在!"); } } else if (dmlType == GlobalConstants.DML_OPERATION_UPDATE || dmlType == GlobalConstants.DML_OPERATION_DELETE) { if (dbContext.Find(entityType, entity.RecordId) == null) { throw new BusinessException(GlobalConstants.EXCEPTION_CODE_DATA_ALREADY_EXISTS, $"Id为{entity.RecordId}的{entityType}数据不存在!"); } } IVerifier verify = GetVerifier(entityType); if (verify == null) { return; } verify.VerifyData(dbContext, entity, dmlType); }