Exemplo n.º 1
0
 public InjectionContext(DataAccessModel model, SqlDatabaseContextInfo contextInfo, Func <SqlDataTypeProvider> defaultProviderFactoryMethod, Func <string, Tuple <bool, object> > parameterNameToValue = null)
 {
     this.model       = model;
     this.contextInfo = contextInfo;
     this.defaultProviderFactoryMethod    = defaultProviderFactoryMethod;
     this.parameterNameToValue            = parameterNameToValue;
     this.typeDescriptorProvider          = this.model.TypeDescriptorProvider;
     this.constraintsDefaultConfiguration = this.model.Configuration.ConstraintDefaultsConfiguration;
 }
Exemplo n.º 2
0
		protected SqlDatabaseContext(DataAccessModel model, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, string databaseName, SqlDatabaseContextInfo contextInfo)
		{
			this.DatabaseName = databaseName;
			this.DataAccessModel = model; 
			this.CommandTimeout = contextInfo.CommandTimeout == null ? null : (TimeSpan?)TimeSpan.FromSeconds(contextInfo.CommandTimeout.Value);
			var categories = contextInfo.Categories ?? "";
			this.ContextCategories = categories.Trim().Length == 0 ? new string[0] : categories.Split(',').Select(c => c.Trim()).ToArray();
			this.SqlDialect = sqlDialect;
			this.SqlDataTypeProvider = sqlDataTypeProvider;
			this.SqlQueryFormatterManager = sqlQueryFormatterManager;
			this.SchemaName = EnvironmentSubstitutor.Substitute(contextInfo.SchemaName);
			this.TableNamePrefix = EnvironmentSubstitutor.Substitute(contextInfo.TableNamePrefix);
		}
Exemplo n.º 3
0
        protected static SqlDataTypeProvider CreateSqlDataTypeProvider(DataAccessModel model, SqlDatabaseContextInfo contextInfo, Func <SqlDataTypeProvider> defaultProviderFactoryMethod)
        {
            SqlDataTypeProvider retval = null;

            if (contextInfo.SqlDataTypeProvider != null)
            {
                if (retval == null)
                {
                    var constructorInfo = contextInfo.SqlDataTypeProvider.GetConstructor(new[] { typeof(SqlDataTypeProvider) });

                    if (constructorInfo != null)
                    {
                        retval = (SqlDataTypeProvider)constructorInfo.Invoke(new object[] { defaultProviderFactoryMethod() });
                    }
                }

                if (retval == null)
                {
                    var constructorInfo = contextInfo.SqlDataTypeProvider.GetConstructors().OrderByDescending(c => c.GetParameters().Length).FirstOrDefault();

                    if (constructorInfo != null)
                    {
                        var context = new InjectionContext(model, contextInfo, defaultProviderFactoryMethod);
                        var args    = context.GetArguments(constructorInfo.GetParameters());

                        retval = (SqlDataTypeProvider)constructorInfo.Invoke(args);
                    }
                }
            }

            if (retval == null)
            {
                retval = defaultProviderFactoryMethod();
            }

            if (retval is DefaultSqlDataTypeProvider defaultSqlDataTypeProvider && contextInfo.SqlDataTypes?.Count > 0)
            {
                var sqlDataTypeContext = new InjectionContext(model, contextInfo, () => retval, c => c == "nullable" ? new Tuple <bool, object>(true, false) : new Tuple <bool, object>(false, false));

                foreach (var type in contextInfo.SqlDataTypes)
                {
                    var constructors = type.GetConstructors().OrderByDescending(c => c.GetParameters().Length).ToList();

                    for (var i = 0; i < constructors.Count; i++)
                    {
                        var constructorInfo = constructors[i];

                        var args = sqlDataTypeContext.GetArguments(constructorInfo.GetParameters());

                        try
                        {
                            var parameters = constructorInfo.GetParameters();

                            var index = parameters.IndexOfAny(c => c.Name == "nullable");

                            if (index >= 0)
                            {
                                args[index] = false;
                                var sqlDataType = (SqlDataType)constructorInfo.Invoke(args);
                                defaultSqlDataTypeProvider.DefineSqlDataType(sqlDataType);

                                args[index] = true;
                                sqlDataType = (SqlDataType)constructorInfo.Invoke(args);
                                defaultSqlDataTypeProvider.DefineSqlDataType(sqlDataType);
                            }
                            else
                            {
                                var sqlDataType = (SqlDataType)constructorInfo.Invoke(args);
                                defaultSqlDataTypeProvider.DefineSqlDataType(sqlDataType);
                            }

                            break;
                        }
                        catch (InvalidOperationException)
                        {
                            if (i == constructors.Count - 1)
                            {
                                throw;
                            }
                        }
                    }
                }
            }
Exemplo n.º 4
0
        protected SqlDatabaseContext(DataAccessModel model, SqlDialect sqlDialect, SqlDataTypeProvider sqlDataTypeProvider, SqlQueryFormatterManager sqlQueryFormatterManager, string databaseName, SqlDatabaseContextInfo contextInfo)
        {
            this.DatabaseName    = databaseName;
            this.DataAccessModel = model;
            this.CommandTimeout  = contextInfo.CommandTimeout == null ? null : (TimeSpan?)TimeSpan.FromSeconds(contextInfo.CommandTimeout.Value);
            var categories = contextInfo.Categories ?? "";

            this.ContextCategories        = categories.Trim().Length == 0 ? new string[0] : categories.Split(',').Select(c => c.Trim()).ToArray();
            this.SqlDialect               = sqlDialect;
            this.SqlDataTypeProvider      = sqlDataTypeProvider;
            this.SqlQueryFormatterManager = sqlQueryFormatterManager;
            this.SchemaName               = EnvironmentSubstitutor.Substitute(contextInfo.SchemaName);
            this.TableNamePrefix          = EnvironmentSubstitutor.Substitute(contextInfo.TableNamePrefix);
        }