Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DbMetadata"/> class.
        /// </summary>
        /// <param name="productName">Name of the product.</param>
        /// <param name="assemblyName">Name of the assembly.</param>
        /// <param name="connectionType">Type of the connection.</param>
        /// <param name="commandType">Type of the command.</param>
        /// <param name="parameterType">Type of the parameter.</param>
        /// <param name="dataAdapterType">Type of the data adapter.</param>
        /// <param name="commandBuilderType">Type of the command builder.</param>
        /// <param name="commandBuilderDeriveParametersMethod">The command builder derive parameters method.</param>
        /// <param name="parameterDbType">Type of the parameter db.</param>
        /// <param name="parameterDbTypeProperty">The parameter db type property.</param>
        /// <param name="parameterIsNullableProperty">The parameter is nullable property.</param>
        /// <param name="parameterNamePrefix">The parameter name prefix.</param>
        /// <param name="exceptionType">Type of the exception.</param>
        /// <param name="useParameterNamePrefixInParameterCollection">if set to <c>true</c> [use parameter name prefix in parameter collection].</param>
        /// <param name="useParameterPrefixInSql">if set to <c>true</c> [use parameter prefix in SQL].</param>
        /// <param name="bindByName">if set to <c>true</c> [bind by name].</param>
        /// <param name="errorCodeExceptionExpression">The error code exception expression.</param>
        public DbMetadata(string productName,
                          string assemblyName,
                          Type connectionType,
                          Type commandType,
                          Type parameterType,
                          Type dataAdapterType,
                          Type commandBuilderType,
                          string commandBuilderDeriveParametersMethod,
                          Type parameterDbType,
                          string parameterDbTypeProperty,
                          string parameterIsNullableProperty,
                          string parameterNamePrefix,
                          Type exceptionType,
                          bool useParameterNamePrefixInParameterCollection,
                          bool useParameterPrefixInSql,
                          bool bindByName,
                          string errorCodeExceptionExpression

            )
        {

            AssertUtils.ArgumentHasText(productName, "ProductName");
            this.productName = productName;
            AssertUtils.ArgumentHasText(assemblyName, "assemblyName", GetErrorMessage() );
            AssertUtils.ArgumentNotNull(connectionType, "connectionType", GetErrorMessage() );
            AssertUtils.ArgumentNotNull(commandType, "commandType", GetErrorMessage());
            AssertUtils.ArgumentNotNull(parameterType, "parameterType", GetErrorMessage());
            AssertUtils.ArgumentNotNull(dataAdapterType, "dataAdapterType", GetErrorMessage());
            AssertUtils.ArgumentNotNull(commandBuilderType, "commandBuilderType", GetErrorMessage());
            AssertUtils.ArgumentHasText(commandBuilderDeriveParametersMethod, "commandBuilderDeriveParametersMethod", GetErrorMessage());
            AssertUtils.ArgumentNotNull(parameterDbType, "parameterDbType", GetErrorMessage());
            AssertUtils.ArgumentHasText(parameterDbTypeProperty, "parameterDbTypeProperty", GetErrorMessage());
            AssertUtils.ArgumentHasText(parameterIsNullableProperty, "parameterIsNullableProperty", GetErrorMessage());
            AssertUtils.ArgumentHasText(parameterNamePrefix, "parameterNamePrefix", GetErrorMessage());
            AssertUtils.ArgumentNotNull(exceptionType, "exceptionType", GetErrorMessage());
            
            this.assemblyName = assemblyName;

            this.connectionType = connectionType;
            this.commandType = commandType;
            this.parameterType = parameterType;
            this.dataAdapterType = dataAdapterType;
            this.commandBuilderType = commandBuilderType;

            if (commandBuilderDeriveParametersMethod.ToLower().Trim().Equals("not supported"))
            {
                supportsDeriveParametersMethod = false;
            }

            if (supportsDeriveParametersMethod)
            {
                this.commandBuilderDeriveParametersMethod =
                    ReflectionUtils.GetMethod(this.commandBuilderType, commandBuilderDeriveParametersMethod,
                                              new Type[] {this.commandType});

                AssertUtils.ArgumentNotNull(this.commandBuilderDeriveParametersMethod,
                                            "commandBuilderDeriveParametersMethod", GetErrorMessage() +
                                                                                    ", could not resolve commandBuilderDeriveParametersMethod " +
                                                                                    commandBuilderDeriveParametersMethod +
                                                                                    " to MethodInfo.  Please check dbproviders.xml entry for correct metadata listing.");
            }

            this.commandType = commandType;

            this.parameterDbType = parameterDbType;

            this.parameterDbTypeProperty = this.parameterType.GetProperty(parameterDbTypeProperty,
                                                     BindingFlags.Instance | BindingFlags.Public);
            AssertUtils.ArgumentNotNull(this.parameterDbTypeProperty, "parameterDbTypeProperty", GetErrorMessage() + 
                ", could not resolve parameterDbTypeProperty " + 
                parameterDbTypeProperty + 
                " to PropertyInfo.  Please check dbproviders.xml entry for correct metadata listing.");

            this.parameterIsNullableProperty = this.parameterType.GetProperty(parameterIsNullableProperty,
                                                     BindingFlags.Instance | BindingFlags.Public);

            AssertUtils.ArgumentNotNull(this.parameterIsNullableProperty, "parameterIsNullableProperty", GetErrorMessage() +
                ", could not resolve parameterIsNullableProperty " +
                parameterIsNullableProperty +
                " to PropertyInfo.  Please check dbproviders.xml entry for correct metadata listing.");
            
            this.parameterNamePrefix = parameterNamePrefix;
            this.exceptionType = exceptionType;
           
            this.useParameterNamePrefixInParameterCollection = useParameterNamePrefixInParameterCollection;
            this.useParameterPrefixInSql = useParameterPrefixInSql;
            this.bindByName = bindByName;

            this.errorCodeExceptionExpression = errorCodeExceptionExpression;
            
            
            errorCodes = new ErrorCodes();

        
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ErrorCodeExceptionTranslator"/> class.
 /// </summary>
 /// <param name="provider">The data provider.</param>
 /// <param name="ec">The error code collection.</param>
 public ErrorCodeExceptionTranslator(IDbProvider provider, ErrorCodes ec)
 {
     DbProvider = provider;
     errorCodes = ec;
 }