Exemplo n.º 1
0
        public void Apply_should_sort_annotated_before_unannotated()
        {
            var table   = new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace);
            var columnA = new EdmProperty(
                "C",
                ProviderRegistry.Sql2008_ProviderManifest.GetStoreType(
                    TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))));

            columnA.SetOrder(2);
            table.AddColumn(columnA);
            table.AddColumn(
                new EdmProperty(
                    "Id",
                    ProviderRegistry.Sql2008_ProviderManifest.GetStoreType(
                        TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)))));

            var database = new EdmModel().Initialize();

            database.AddEntitySet("ES", table);

            ((IDbConvention <EntityType>) new ColumnOrderingConvention()).Apply(table, database);

            Assert.Equal(2, table.Properties.Count);
            Assert.Equal("C", table.Properties.First().Name);
        }
        protected virtual void ConfigureColumn(EdmProperty column, EntityType table, DbProviderManifest providerManifest)
        {
            ConfigureColumnName(column, table);

            ConfigureAnnotations(column);

            if (!string.IsNullOrWhiteSpace(ColumnType))
            {
                column.PrimitiveType = providerManifest.GetStoreTypeFromName(ColumnType);
            }

            if (ColumnOrder != null)
            {
                column.SetOrder(ColumnOrder.Value);
            }

            var storeType
                = providerManifest.GetStoreTypes()
                  .SingleOrDefault(t => t.Name.Equals(column.TypeName, StringComparison.OrdinalIgnoreCase));

            if (storeType != null)
            {
                storeType.FacetDescriptions.Each(f => Configure(column, f));
            }

            column.SetConfiguration(this);
        }
        public void Apply_should_order_by_annotation_if_given()
        {
            var table   = new EntityType("T", XmlConstants.TargetNamespace_3, DataSpace.SSpace);
            var columnA = new EdmProperty(
                "C",
                ProviderRegistry.Sql2008_ProviderManifest.GetStoreType(
                    TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))));

            columnA.SetOrder(2);
            table.AddColumn(columnA);
            var columnB = new EdmProperty(
                "Id",
                ProviderRegistry.Sql2008_ProviderManifest.GetStoreType(
                    TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))));

            columnB.SetOrder(1);
            table.AddColumn(columnB);

            var database = new EdmModel(DataSpace.CSpace);

            database.AddEntitySet("ES", table);

            (new ColumnOrderingConvention()).Apply(table, new DbModel(null, database));

            Assert.Equal(2, table.Properties.Count);
            Assert.Equal("Id", table.Properties.First().Name);
        }
Exemplo n.º 4
0
        internal virtual void Configure(
            EdmProperty column, EntityType table, DbProviderManifest providerManifest,
            bool allowOverride = false,
            bool fillFromExistingConfiguration = false)
        {
            DebugCheck.NotNull(column);
            DebugCheck.NotNull(table);
            DebugCheck.NotNull(providerManifest);

            var existingConfiguration = column.GetConfiguration() as PrimitivePropertyConfiguration;

            if (existingConfiguration != null)
            {
                var overridable = column.GetAllowOverride();

                string errorMessage;
                if ((existingConfiguration.OverridableConfigurationParts
                     & OverridableConfigurationParts.OverridableInSSpace)
                    != OverridableConfigurationParts.OverridableInSSpace &&
                    !overridable &&
                    !allowOverride &&
                    !fillFromExistingConfiguration &&
                    !existingConfiguration.IsCompatible(this, inCSpace: false, errorMessage: out errorMessage))
                {
                    throw Error.ConflictingColumnConfiguration(column.Name, table.Name, errorMessage);
                }

                FillFrom(existingConfiguration, inCSpace: false);
            }

            ConfigureColumnName(column, table);

            if (!string.IsNullOrWhiteSpace(ColumnType))
            {
                column.PrimitiveType = providerManifest.GetStoreTypeFromName(ColumnType);
            }

            if (ColumnOrder != null)
            {
                column.SetOrder(ColumnOrder.Value);
            }

            var storeType
                = providerManifest.GetStoreTypes()
                  .SingleOrDefault(t => t.Name.Equals(column.TypeName, StringComparison.OrdinalIgnoreCase));

            if (storeType != null)
            {
                storeType.FacetDescriptions.Each(f => Configure(column, f));
            }

            column.SetConfiguration(this);
            column.SetAllowOverride(allowOverride);
        }
Exemplo n.º 5
0
        protected virtual void ConfigureColumn(
            EdmProperty column,
            EntityType table,
            DbProviderManifest providerManifest)
        {
            this.ConfigureColumnName(column, table);
            this.ConfigureAnnotations(column);
            if (!string.IsNullOrWhiteSpace(this.ColumnType))
            {
                column.PrimitiveType = providerManifest.GetStoreTypeFromName(this.ColumnType);
            }
            if (this.ColumnOrder.HasValue)
            {
                column.SetOrder(this.ColumnOrder.Value);
            }
            PrimitiveType primitiveType = providerManifest.GetStoreTypes().SingleOrDefault <PrimitiveType>((Func <PrimitiveType, bool>)(t => t.Name.Equals(column.TypeName, StringComparison.OrdinalIgnoreCase)));

            if (primitiveType != null)
            {
                primitiveType.FacetDescriptions.Each <FacetDescription>((Action <FacetDescription>)(f => this.Configure(column, f)));
            }
            column.SetConfiguration((object)this);
        }