public void Configure_is_max_length_on_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<Customer>().Property(c => c.CustomerType).IsMaxLength();

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            databaseMapping.Assert<Customer>(c => c.CustomerType).FacetEqual(true, f => f.IsMaxLength);
        }
        public void Configure_is_max_length_on_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<Customer>().Property(c => c.CustomerType).IsMaxLength();

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.Assert<Customer>(c => c.CustomerType).FacetEqual(true, f => f.IsMaxLength);
        }
        public void Duplicate_property_names_differing_by_case_are_uniquified()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<DuplicatePropNames>();

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            databaseMapping.Assert<DuplicatePropNames>().HasColumns("Id", "name", "NAME");
        }
        public void Duplicate_property_names_differing_by_case_are_uniquified()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<DuplicatePropNames>();

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.Assert<DuplicatePropNames>().HasColumns("Id", "name", "NAME");
        }
Exemplo n.º 5
0
        public void Build_model_for_a_single_type_with_a_enum_key()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<Enum_Product_PK>();

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            Assert.Equal(1, databaseMapping.EntityContainerMappings.Single().EntitySetMappings.Count());
        }
        public void Decimal_property_gets_default_precision_by_convention()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<BillOfMaterials>();

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            databaseMapping.Assert<BillOfMaterials>(b => b.PerAssemblyQty).FacetEqual((byte)18, f => f.Precision);
            databaseMapping.Assert<BillOfMaterials>(b => b.PerAssemblyQty).FacetEqual((byte)2, f => f.Scale);
        }
        public void Decimal_property_gets_default_precision_by_convention()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<BillOfMaterials>();

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.Assert<BillOfMaterials>(b => b.PerAssemblyQty).FacetEqual((byte)18, f => f.Precision);
            databaseMapping.Assert<BillOfMaterials>(b => b.PerAssemblyQty).FacetEqual((byte)2, f => f.Scale);
        }
Exemplo n.º 8
0
        public void Annotation_in_derived_class_when_base_class_processed_after_derived_class()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<StyledProduct>();
            modelBuilder.Entity<Product>();

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.Assert<StyledProduct>(s => s.Style).FacetEqual(150, f => f.MaxLength);
        }
        public void Build_model_after_configuring_entity_set_name()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<TransactionHistoryArchive>().HasEntitySetName("Foos");

            var databaseMapping = BuildMapping(modelBuilder);

            Assert.True(databaseMapping.Model.Containers.Single().EntitySets.Any(es => es.Name == "Foos"));
        }
        public void Build_model_for_mapping_to_duplicate_tables_different_schemas()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<Customer>().ToTable("tbl");
            modelBuilder.Entity<Product>().ToTable("tbl", "other");

            var databaseMapping = BuildMapping(modelBuilder);

            Assert.True(databaseMapping.Database.GetEntitySets().Any(s => s.Schema == "dbo"));
            Assert.True(databaseMapping.Database.GetEntitySets().Any(s => s.Schema == "other"));

            databaseMapping.Assert<Customer>().DbEqual("tbl", t => t.Table);
            databaseMapping.Assert<Product>().DbEqual("tbl", t => t.Table);
        }
        public void Map_IA_column_names_several_times_last_wins()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<SpecialOfferProduct>()
                        .HasKey(p => p.ProductID);

            modelBuilder.Entity<SpecialOffer>()
                        .HasKey(o => o.SpecialOfferID)
                        .HasMany(o => o.SpecialOfferProducts)
                        .WithRequired(p => p.SpecialOffer)
                        .Map(
                            mc =>
                                {
                                    mc.MapKey("BadFK");
                                    mc.ToTable("BadTable");
                                    mc.MapKey("TheFK");
                                    mc.ToTable("SpecialOfferProducts");
                                });

            var databaseMapping = BuildMapping(modelBuilder);

            Assert.Equal(2, databaseMapping.Database.EntityTypes.Count());

            databaseMapping.Assert<SpecialOfferProduct>()
                           .HasColumns("ProductID", "SpecialOfferID", "rowguid", "ModifiedDate", "TheFK")
                           .HasForeignKeyColumn("TheFK");
        }
        public void Configure_store_type_on_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<Customer>().Property(c => c.CustomerType).HasColumnType("ntext");

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);
            databaseMapping.AssertValid();

            databaseMapping.Assert<Customer>(c => c.CustomerType).DbEqual("ntext", f => f.TypeName);
        }
        public void Build_model_for_entity_splitting_difference_schemas()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<Vendor>()
                .Map(m =>
                     {
                         m.Properties(v1 => new
                                            {
                                                v1.VendorID,
                                                v1.Name,
                                                v1.PreferredVendorStatus,
                                                v1.AccountNumber,
                                                v1.ActiveFlag,
                                                v1.CreditRating
                                            });
                         m.ToTable("Vendor", "vendors");
                     })
                .Map(m =>
                     {
                         m.Properties(v2 => new { v2.VendorID, v2.ModifiedDate, v2.PurchasingWebServiceURL });
                         m.ToTable("VendorDetails", "details");
                     });

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            Assert.True(databaseMapping.Database.Schemas.Any(s => s.DatabaseIdentifier == "vendors"));
            Assert.True(databaseMapping.Database.Schemas.Any(s => s.DatabaseIdentifier == "details"));
        }
        public void TableNameAttribute_affects_only_base_in_TPT()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<TNAttrBase>()
                .Map<TNAttrDerived>(mc => mc.ToTable("B"));

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            databaseMapping.Assert<TNAttrBase>("A");
            databaseMapping.Assert<TNAttrDerived>("B");
        }
        public void Build_model_after_configuring_entity_set_name()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<TransactionHistoryArchive>().HasEntitySetName("Foos");

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            Assert.True(databaseMapping.Model.Containers.Single().EntitySets.Any(es => es.Name == "Foos"));
        }
        public void Configure_identity_on_non_key_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder
                .Entity<WorkOrder>()
                .Property(w => w.OrderQty)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            databaseMapping.Assert<WorkOrder>(w => w.OrderQty)
                .AnnotationEqual(StoreGeneratedPattern.Identity, "StoreGeneratedPattern");
            databaseMapping.Assert<WorkOrder>(w => w.WorkOrderID)
                .AnnotationNull("StoreGeneratedPattern");
        }
        public void Configure_nullable_scalar_property_as_required_using_api()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<Product>().Property(p => p.ProductSubcategoryID).IsRequired();

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            databaseMapping.Assert<Product>(p => p.ProductSubcategoryID).IsFalse(t => t.Nullable);
        }
        public void Configure_IsConcurrencyToken_using_configuration()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            var configuration = new ComplexTypeConfiguration<UnitMeasure>();

            configuration.Property(u => u.UnitMeasureCode).IsConcurrencyToken();

            modelBuilder.Configurations.Add(configuration);

            modelBuilder.Entity<BillOfMaterials>().Ignore(b => b.Product);
            modelBuilder.Entity<BillOfMaterials>().Ignore(b => b.Product1);

            var databaseMapping = BuildMapping(modelBuilder);
            databaseMapping.AssertValid();

            Assert.Equal(
                ConcurrencyMode.Fixed,
                databaseMapping.Model.Namespaces.Single().ComplexTypes.Single()
                    .Properties.Single(p => p.Name == "UnitMeasureCode").ConcurrencyMode);
        }
        public void Configure_identity_on_nullable_scalar_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder
                .Entity<SpecialOffer>()
                .Property(s => s.MaxQty)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);
            databaseMapping.AssertValid();

            databaseMapping.Assert<SpecialOffer>(s => s.MaxQty)
                .AnnotationEqual(StoreGeneratedPattern.Identity, "StoreGeneratedPattern");
            databaseMapping.Assert<SpecialOffer>(s => s.MaxQty).DbIsFalse(t => t.Nullable);
        }
        public void Overridden_nullable_scalar_key_becomes_nullable_scalar_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder
                .Entity<Location>()
                .HasKey(l => l.Name);

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);
            databaseMapping.AssertValid();

            databaseMapping.Assert<Location>(l => l.LocationID).IsTrue(t => t.Nullable);
        }
        public void Configure_nullable_scalar_key()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<Location>();

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);
            databaseMapping.AssertValid();

            databaseMapping.Assert<Location>(l => l.LocationID).IsFalse(t => t.Nullable);
        }
Exemplo n.º 22
0
        public void TableNameAttribute_affects_only_base_in_TPT()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<TNAttrBase>()
                .Map<TNAttrDerived>(mc => mc.ToTable("B"));

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.Assert<TNAttrBase>("A");
            databaseMapping.Assert<TNAttrDerived>("B");
        }
        public void Annotation_in_derived_class_when_base_class_processed_after_derived_class()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<StyledProduct>();
            modelBuilder.Entity<Product>();

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            databaseMapping.Assert<StyledProduct>(s => s.Style).FacetEqual(150, f => f.MaxLength);
        }
        public void Configure_HasColumnName_using_configuration_can_be_overriden_using_api()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            var configuration = new EntityTypeConfiguration<UnitMeasure>();

            configuration.HasKey(u => u.UnitMeasureCode);
            configuration.Property(u => u.UnitMeasureCode).HasColumnName("Code");

            modelBuilder.Configurations.Add(configuration);

            modelBuilder.Entity<UnitMeasure>().Property(u => u.UnitMeasureCode).HasColumnName("UnitCode");

            var databaseMapping = BuildMapping(modelBuilder);
            databaseMapping.AssertValid();

            databaseMapping.Assert<UnitMeasure>("UnitMeasures").HasColumns("UnitCode", "Name");
        }
        public void TableNameAttribute_affects_table_name_in_TPH()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<TNAttrBase>()
                .Map(mc => mc.Requires("disc").HasValue("A"))
                .Map<TNAttrDerived>(mc => mc.Requires("disc").HasValue("B"));

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            databaseMapping.Assert<TNAttrBase>("A");
            databaseMapping.AssertMapping<TNAttrBase>("A", false).HasColumnCondition("disc", "A");
            databaseMapping.Assert<TNAttrDerived>("A");
            databaseMapping.AssertMapping<TNAttrDerived>("A").HasColumnCondition("disc", "B");
        }
        public void Mapping_IA_column_name_to_existing_one_throws()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<SpecialOfferProduct>()
                        .HasKey(p => p.ProductID);

            modelBuilder.Entity<SpecialOffer>()
                        .HasKey(o => o.SpecialOfferID)
                        .HasMany(o => o.SpecialOfferProducts)
                        .WithRequired(p => p.SpecialOffer)
                        .Map(mc => mc.MapKey("SpecialOfferID"));

            Assert.Throws<ModelValidationException>(
                () => BuildMapping(modelBuilder));
        }
        public void Build_model_for_mapping_to_duplicate_tables_different_schemas()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<Customer>().ToTable("tbl");
            modelBuilder.Entity<Product>().ToTable("tbl", "other");

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            Assert.True(databaseMapping.Database.Schemas.Any(s => s.DatabaseIdentifier == "dbo"));
            Assert.True(databaseMapping.Database.Schemas.Any(s => s.DatabaseIdentifier == "other"));

            databaseMapping.Assert<Customer>().DbEqual("tbl", t => t.DatabaseIdentifier);
            databaseMapping.Assert<Product>().DbEqual("tbl", t => t.DatabaseIdentifier);
        }
        public void Setting_IA_FK_name_also_changes_condition_column_name()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<Repro150565_BaseDependent>().HasKey(e => e.Key1);
            modelBuilder.Entity<Repro150565_Dependent>().Map(mapping => mapping.ToTable("Dependent"));
            modelBuilder.Entity<Repro150565_Dependent>().HasOptional(e => e.PrincipalNavigation).WithMany(
                e => e.DependentNavigation)
                        .Map(m => m.MapKey("IndependentColumn1"));
            modelBuilder.Entity<Repro150565_BaseDependent>().Map(mapping => mapping.ToTable("BaseDependent"));

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.Assert<Repro150565_Dependent>()
                           .HasColumn("IndependentColumn1");
            Assert.Equal(
                "IndependentColumn1",
                databaseMapping.EntityContainerMappings.Single().AssociationSetMappings.ElementAt(0).ColumnConditions.ElementAt(0).ColumnProperty
                                                          .Name);
        }
        public void Build_model_with_dotted_table_name_and_dotted_schema_configured()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<SalesPerson>().Map(mc => mc.ToTable("sales.A.B.tbl_sp"));
            modelBuilder.Entity<Customer>();

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            Assert.True(databaseMapping.Database.Schemas.Any(s => s.DatabaseIdentifier == "sales.A.B"));
            Assert.True(databaseMapping.Database.Schemas.Any(s => s.DatabaseIdentifier == "dbo"));
        }
        public void Configure_HasColumnName_using_api()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<UnitMeasure>().HasKey(u => u.UnitMeasureCode);
            modelBuilder.Entity<UnitMeasure>().Property(u => u.UnitMeasureCode).HasColumnName("Code");

            var databaseMapping = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);
            databaseMapping.AssertValid();

            databaseMapping.Assert<UnitMeasure>("UnitMeasures").HasColumns("Code", "Name");
        }