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 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);
        }
        public void Configure_has_max_length_on_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

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

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

            databaseMapping.AssertValid();

            databaseMapping.Assert <Customer>(c => c.CustomerType).FacetEqual(40, f => f.MaxLength);
        }
Beispiel #4
0
        public void Configure_store_type_on_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

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

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.AssertValid();

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

            modelBuilder.Entity <ProductDescription>();
            modelBuilder.ComplexType <RowDetails>();

            var databaseMapping = BuildMapping(modelBuilder);

            Assert.Equal(1, databaseMapping.EntityContainerMappings.Single().EntitySetMappings.Count());
            Assert.Equal(1, databaseMapping.Model.ComplexTypes.Count());
        }
Beispiel #6
0
        public void Build_model_for_type_with_a_non_public_complex_type_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity <TransactionHistory>()
            .HasKey(th => th.TransactionID);
            modelBuilder.ComplexType <RowDetails>();

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.Assert <TransactionHistory>(th => th.RowDetails);
        }
        public void Build_model_for_a_single_type_with_a_complex_type()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity <ProductDescription>();
            modelBuilder.ComplexType <RowDetails>();

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

            Assert.Equal(1, databaseMapping.EntityContainerMappings.Single().EntitySetMappings.Count());
            Assert.Equal(1, databaseMapping.Model.Namespaces.Single().ComplexTypes.Count);
        }
        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");
        }
Beispiel #9
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 Build_model_for_type_with_a_non_public_complex_type_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity <TransactionHistory>()
            .HasKey(th => th.TransactionID);
            modelBuilder.ComplexType <RowDetails>();

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

            databaseMapping.Assert <TransactionHistory>(th => th.RowDetails);
        }
            public void Remove_derived_encapsulated_lightweight_convention()
            {
                var modelBuilder = new AdventureWorksModelBuilder();

                modelBuilder.Entity <LightweightEntity>();
                modelBuilder.Conventions.Add <LightweightTableConvention>();
                modelBuilder.Conventions.Remove <LightweightTableConvention>();

                var databaseMapping = BuildMapping(modelBuilder);

                Assert.False(databaseMapping.Database.GetEntitySets().Any(t => t.Table == "TheTable"));
            }
Beispiel #12
0
        public void Configure_nullable_scalar_key()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity <Location>();

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.AssertValid();

            databaseMapping.Assert <Location>(l => l.LocationID).IsFalse(t => t.Nullable);
        }
Beispiel #13
0
        public void Configure_has_max_length_on_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

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

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.AssertValid();

            databaseMapping.Assert <Customer>(c => c.CustomerType).FacetEqual(40, f => f.MaxLength);
        }
        public void Build_model_containing_a_complex_type_by_convention()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity <BillOfMaterials>();

            var databaseMapping = modelBuilder.BuildAndValidate(
                ProviderRegistry.Sql2008_ProviderInfo,
                typeof(UnitMeasure));

            Assert.Equal(1, databaseMapping.EntityContainerMappings.Single().EntitySetMappings.Count());
            Assert.Equal(1, databaseMapping.Model.Namespaces.Single().ComplexTypes.Count);
        }
Beispiel #15
0
        public void Build_model_containing_a_complex_type_with_instance_cspace_configuration_override()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity <ProductDescription>()
            .Property(pd => pd.RowDetails.rowguid)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
            modelBuilder.ComplexType <RowDetails>()
            .Property(rd => rd.rowguid)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            Assert.Throws <InvalidOperationException>(() => BuildMapping(modelBuilder));
        }
Beispiel #16
0
        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.ComplexTypes.Single()
                .Properties.Single(p => p.Name == "UnitMeasureCode").ConcurrencyMode);
        }
            public void Add_custom_model_convention()
            {
                var modelBuilder = new AdventureWorksModelBuilder();

                modelBuilder.Entity <Customer>();
                modelBuilder.Conventions.Add <EntitySetNamingConvention>();

                var databaseMapping = BuildMapping(modelBuilder);

                Assert.Equal(
                    1,
                    databaseMapping.Model.GetEntitySets().Count(
                        t => t.Name == "CustomersFoo"));
            }
        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 Add_custom_model_convention()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<Customer>();
            modelBuilder.Conventions.Add<EntitySetNamingConvention>();

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

            Assert.Equal(
                1,
                databaseMapping.Model.GetEntitySets().Count(
                    t => t.Name == "CustomersFoo"));
        }
Beispiel #20
0
        public void Overridden_nullable_scalar_key_becomes_nullable_scalar_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

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

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.AssertValid();

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

            modelBuilder.Entity <Customer>()
            .HasKey(e => new { e.CustomerID, e.AccountNumber })
            .ConfigureKey()
            .IsClustered(false);

            modelBuilder.Entity <Customer>()
            .HasIndex(e => new { e.CustomerType, e.rowguid })
            .IsUnique()
            .IsClustered();

            var model = modelBuilder.Build(ProviderRegistry.Sql2008_ProviderInfo);

            {
                var indexAttribute = ConfiguredPrimaryKeyIndexAttribute(model, "Customer");

                indexAttribute.AssertConfiguration(null, null, null, false);
            }

            {
                var indexAttributes = ConfiguredIndexAttributes(model, "Customer", "CustomerType");
                Assert.Single(indexAttributes);

                indexAttributes.Single().AssertConfiguration("IX_CustomerType_rowguid", 0, true, true);
            }

            {
                var indexAttributes = ConfiguredIndexAttributes(model, "Customer", "rowguid");
                Assert.Single(indexAttributes);

                indexAttributes.Single().AssertConfiguration("IX_CustomerType_rowguid", 1, true, true);
            }
        }
Beispiel #22
0
        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 = BuildMapping(modelBuilder);

            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 Configure_has_key_on_property_creates_index()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity <Customer>()
            .HasKey(e => e.CustomerID);

            var model = modelBuilder.Build(ProviderRegistry.Sql2008_ProviderInfo);

            {
                var indexAttribute = ConfiguredPrimaryKeyIndexAttribute(model, "Customer");

                indexAttribute.AssertConfiguration(null, null, null, null);
            }
        }
Beispiel #24
0
        public void Build_model_containing_a_complex_type_with_configuration()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity <ProductDescription>();
            modelBuilder
            .ComplexType <RowDetails>()
            .Property(rd => rd.rowguid)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed)
            .HasColumnName("ROW_GUID");

            var databaseMapping = BuildMapping(modelBuilder);

            Assert.Equal(1, databaseMapping.EntityContainerMappings.Single().EntitySetMappings.Count());
        }
Beispiel #25
0
        public void Configure_identity_on_non_key_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

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

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.Assert <WorkOrder>(w => w.OrderQty)
            .MetadataPropertyEqual("Identity", "StoreGeneratedPattern");
            databaseMapping.Assert <WorkOrder>(w => w.WorkOrderID)
            .AnnotationNull("StoreGeneratedPattern");
        }
        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_has_index_on_property_index_ordered()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity <Customer>()
            .HasIndex(e => e.CustomerID);

            var model = modelBuilder.Build(ProviderRegistry.Sql2008_ProviderInfo);

            {
                var indexAttributes = ConfiguredIndexAttributes(model, "Customer", "CustomerID");
                Assert.Single(indexAttributes);

                indexAttributes.Single().AssertConfiguration(null, -1, null, null);
            }
        }
        public void Configure_configure_key_on_property_index_clustered()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity <Customer>()
            .ConfigureKey()
            .IsClustered(true);

            var model = modelBuilder.Build(ProviderRegistry.Sql2008_ProviderInfo);

            {
                var indexAttribute = ConfiguredPrimaryKeyIndexAttribute(model, "Customer");

                indexAttribute.AssertConfiguration(null, null, null, true);
            }
        }
Beispiel #29
0
        public void Build_model_containing_a_complex_type_with_has_max_length_configuration()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.ComplexType <LargePhoto>();
            modelBuilder.Entity <ProductPhoto>()
            .Property(p => p.LargePhoto.Photo)
            .HasColumnType("binary")
            .HasMaxLength(42);

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.Assert <LargePhoto>(l => l.Photo)
            .FacetEqual(42, f => f.MaxLength)
            .DbEqual(42, f => f.MaxLength);
        }
Beispiel #30
0
        public void Configure_identity_on_nullable_scalar_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

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

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.AssertValid();

            databaseMapping.Assert <SpecialOffer>(s => s.MaxQty)
            .MetadataPropertyEqual("Identity", "StoreGeneratedPattern");
            databaseMapping.Assert <SpecialOffer>(s => s.MaxQty).DbIsFalse(t => t.Nullable);
        }