public CanonicalFunctionMapper(ITypeConverter converter)
        {
            this.converter = new EdmTypeConverter(converter);
            this.mappings = new Dictionary<string, Func<EdmFunction, Expression[], Expression>>();

            this.AddStringMappings();
            this.AddDateTimeMappings();
            this.AddMathMappings();
            this.AddBitwiseMappings();
            this.AddMiscMappings();
        }
        public CanonicalContainer(ItemCollection source, EdmTypeConverter converter)
        {
            this.converter = converter;
            this.containers = source.GetItems<EntityContainer>().ToList();

            this.entities = new Lazy<ReadOnlyCollection<EntityInfo>>(() =>
                this.GetEntities()
                    .ToList()
                    .AsReadOnly());

            this.associations = new Lazy<ReadOnlyCollection<AssociationInfo>>(() =>
                this.GetAssociations()
                    .ToList()
                    .AsReadOnly());
        }
Beispiel #3
0
        public static DbSchema CreateDbSchema(StoreItemCollection edmStoreSchema)
        {
            EdmTypeConverter converter = new EdmTypeConverter(new DefaultTypeConverter());
            CanonicalContainer container = new CanonicalContainer(edmStoreSchema, converter);

            IBareSchema bareSchema = new DynamicBareSchema(container);

            TableConfigurationGroup tableConfig = new TableConfigurationGroup();
            tableConfig.Register(new BareSchemaConfiguration(bareSchema));
            tableConfig.Register<PrimaryKeyConfiguration>();
            tableConfig.Register<IdentityConfiguration>();
            tableConfig.Register<GeneratedGuidConfiguration>();
            tableConfig.Register<NotNullConfiguration>();
            tableConfig.Register<VarcharLimitConfiguration>();
            tableConfig.Register<CharLimitConfiguration>();
            tableConfig.Register<IndexConfiguration>();

            DbSchemaBuilder schemaBuilder = new DbSchemaBuilder();

            foreach (EntityInfo entityInfo in container.Entities)
            {
                DbTableInfoBuilder tableBuilder = new DbTableInfoBuilder();

                // Run all configurations
                tableConfig.Configure(entityInfo, tableBuilder);

                schemaBuilder.Register(tableBuilder);
            }

            RelationConfigurationGroup associationConfig = new RelationConfigurationGroup();
            associationConfig.Register<RelationConfiguration>();

            foreach (AssociationInfo associationInfo in container.Associations)
            {
                associationConfig.Configure(associationInfo, schemaBuilder);
            }

            return schemaBuilder.Create();
        }
        private IEnumerable<EntityPropertyInfo> GetProperties(
            IEnumerable<EdmProperty> props,
            EdmTypeConverter converter)
        {
            var groups = props.GroupBy(x => x.GetColumnName());

            foreach (var group in groups)
            {
                var prop = group.First();

                var name = prop.GetColumnName();
                var facets = converter.GetTypeFacets(prop.TypeUsage);
                var clrType = converter.Convert(prop.TypeUsage);
                var indexes = GetIndexes(prop).ToList();

                // TODO: verify conflict

                yield return new EntityPropertyInfo(name, clrType, facets, indexes);
            }
        }