Exemplo n.º 1
0
        public void UpdateFromConfig(DataContextElement dataContextConfig)
        {
            List <DataTypeMappingElement> newTypeMappings    = new List <DataTypeMappingElement>();
            List <DataTypeMappingElement> parentTypeMappings = dataContextConfig.TypeMappings.Where(typeMapping => !Tables.ContainsKey(typeMapping.ObjectType)).ToList();

            newTypeMappings.AddRange(parentTypeMappings);

            parentTypeMappings.ForEach(parentTypeMapping => AddChildTypeMappings(newTypeMappings, parentTypeMapping));

            if (newTypeMappings != null)
            {
                using (SqlConnection sqlConn = new SqlConnection(DBConnectionString))
                {
                    sqlConn.Open();

                    newTypeMappings.ForEach(typeMapping =>
                                            SchemaTables.Add(typeMapping, sqlConn.GetSchema("Columns", new string[] { sqlConn.Database, null, typeMapping.TableName, null })));
                }

                // add table data for each config and schema pair
                if (SchemaTables != null)
                {
                    newTypeMappings.ForEach(typeMapping =>
                    {
                        if (SchemaTables.ContainsKey(typeMapping))
                        {
                            Tables.Add(typeMapping.ObjectType, new TableData(this, typeMapping));
                        }
                    });
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Register table data for given type - if type is not a valid data type, throw an exception
        /// </summary>
        public void AddDataContext(DataContextElement dataContextConfig)
        {
            if (!DataContextsByName.ContainsKey(dataContextConfig.ConnectionString.Name))
            {
                DataContextsByName.Add(dataContextConfig.ConnectionString.Name, new DataContext(ComponentContainer, dataContextConfig.ConnectionString.Name, dataContextConfig.ConnectionString.ConnectionString));
            }

            DataContext dataContext = DataContextsByName[dataContextConfig.ConnectionString.Name];

            dataContext.UpdateFromConfig(dataContextConfig);

            RegisterTypes(dataContext, dataContextConfig.TypeMappings.Cast <DataTypeMappingElement>());
        }