Ejemplo n.º 1
0
        private static InterfaceConfigurationElement BuildInterfaceConfigurationElement(
            DataTypeDescriptor dataTypeDescriptor,
            InterfaceConfigurationElement existingElement = null,
            bool updateTableNames = false)
        {
            var propertyMappings = new PropertyNameMappingConfigurationElementCollection();
            //foreach (DataFieldDescriptor field in dataTypeDescriptor.Fields)
            //{
            //    propertyMappings.Add(field.Name, field.Name);
            //}

            var keyInfo = new SimpleNameTypeConfigurationElementCollection();

            foreach (DataFieldDescriptor field in dataTypeDescriptor.KeyFields)
            {
                keyInfo.Add(field.Name, field.InstanceType);
            }

            var stores = new StoreConfigurationElementCollection();

            // Fix logic for the case of a localized interface without languages
            foreach (DataScopeIdentifier dataScope in dataTypeDescriptor.DataScopes)
            {
                foreach (var culture in SqlDataProviderStoreManipulator.GetCultures(dataTypeDescriptor))
                {
                    string tableName = null;

                    if (!updateTableNames && existingElement != null)
                    {
                        foreach (StoreConfigurationElement table  in existingElement.ConfigurationStores)
                        {
                            if (table.DataScope == dataScope.Name && table.CultureName == culture.Name)
                            {
                                tableName = table.TableName;
                                break;
                            }
                        }
                    }

                    tableName = tableName ?? DynamicTypesCommon.GenerateTableName(dataTypeDescriptor, dataScope, culture);

                    stores.Add(new StoreConfigurationElement {
                        TableName = tableName, DataScope = dataScope.Name, CultureName = culture.Name
                    });
                }
            }

            return(new InterfaceConfigurationElement
            {
                DataTypeId = dataTypeDescriptor.DataTypeId,
                IsGeneratedType = dataTypeDescriptor.IsCodeGenerated,
                ConfigurationStores = stores,
                ConfigurationPropertyNameMappings = propertyMappings,
                ConfigurationDataIdProperties = keyInfo,
                ConfigurationPropertyInitializers = new SimpleNameTypeConfigurationElementCollection()
            });
        }
        private static InterfaceConfigurationElement BuildInterfaceConfigurationElement(
            DataTypeDescriptor dataTypeDescriptor,
            InterfaceConfigurationElement existingElement = null,
            bool updateTableNames = false)
        {
            var propertyMappings = new PropertyNameMappingConfigurationElementCollection();
            //foreach (DataFieldDescriptor field in dataTypeDescriptor.Fields)
            //{
            //    propertyMappings.Add(field.Name, field.Name);
            //}

            var keyInfo = new SimpleNameTypeConfigurationElementCollection();
            foreach (DataFieldDescriptor field in dataTypeDescriptor.KeyFields)
            {
                keyInfo.Add(field.Name, field.InstanceType);
            }

            var stores = new StoreConfigurationElementCollection();
            // Fix logic for the case of a localized interface without languages
            foreach (DataScopeIdentifier dataScope in dataTypeDescriptor.DataScopes)
            {
                foreach (var culture in SqlDataProviderStoreManipulator.GetCultures(dataTypeDescriptor))
                {
                    string tableName = null;

                    if (!updateTableNames && existingElement != null)
                    {
                        foreach (StoreConfigurationElement table  in existingElement.ConfigurationStores)
                        {
                            if (table.DataScope == dataScope.Name && table.CultureName == culture.Name)
                            {
                                tableName = table.TableName;
                                break;
                            }
                        }

                    }

                    tableName = tableName ?? DynamicTypesCommon.GenerateTableName(dataTypeDescriptor, dataScope, culture);

                    stores.Add(new StoreConfigurationElement {TableName = tableName, DataScope = dataScope.Name, CultureName = culture.Name});
                }
            }

            return new InterfaceConfigurationElement
            {
                DataTypeId = dataTypeDescriptor.DataTypeId,
                IsGeneratedType = dataTypeDescriptor.IsCodeGenerated,
                ConfigurationStores = stores,
                ConfigurationPropertyNameMappings = propertyMappings,
                ConfigurationDataIdProperties = keyInfo,
                ConfigurationPropertyInitializers = new SimpleNameTypeConfigurationElementCollection()
            };
        }