Beispiel #1
0
        public void HasKey_throws_on_complex_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.ComplexType <CustomerDiscount>();

            Assert.Throws <InvalidOperationException>(
                () => modelBuilder.Entity <Customer>().HasKey(c => c.CustomerDiscount))
            .ValidateMessage("ModelBuilder_KeyPropertiesMustBePrimitive", "CustomerDiscount", typeof(Customer));
        }
Beispiel #2
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 #3
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 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);
        }
Beispiel #6
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 #7
0
        public void Build_model_containing_a_complex_type_with_instance_cspace_configuration()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

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

            var databaseMapping = BuildMapping(modelBuilder);

            Assert.Equal(2, databaseMapping.EntityContainerMappings.Single().EntitySetMappings.Count());
        }
Beispiel #8
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 #9
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);
        }
        public void Build_model_containing_a_complex_type_with_instance_configuration()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity <ProductDescription>()
            .Property(pd => pd.RowDetails.rowguid)
            .HasColumnName("ROW_GUID");
            modelBuilder.ComplexType <RowDetails>()
            .Property(rd => rd.rowguid)
            .HasColumnName("row_guid");
            modelBuilder.Entity <Contact>();

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

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

            modelBuilder.Entity <BillOfMaterials>().Ignore(b => b.Product);
            modelBuilder.Entity <BillOfMaterials>().Ignore(b => b.Product1);
            modelBuilder.ComplexType <UnitMeasure>().Property(u => u.UnitMeasureCode).IsConcurrencyToken();

            var databaseMapping = BuildMapping(modelBuilder);

            databaseMapping.AssertValid();

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

            modelBuilder.Entity <BillOfMaterials>();
            modelBuilder.ComplexType <UnitMeasure>();

            using (var typeConfiguration = new DynamicTypeDescriptionConfiguration <BillOfMaterials>())
            {
                typeConfiguration.SetPropertyAttributes(t => t.UnitMeasure, new RequiredAttribute());

                var databaseMapping = BuildMapping(modelBuilder);

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

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

            var databaseMapping = BuildMapping(modelBuilder);

            Assert.Equal(
                "Identity",
                databaseMapping.Model
                .ComplexTypes.Single()
                .Properties.Single(p => p.Name == "OrderQty")
                .MetadataProperties.Single(a => a.Name.EndsWith("StoreGeneratedPattern")).Value);
        }
        public void Configure_identity_on_complex_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

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

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

            Assert.Equal(
                StoreGeneratedPattern.Identity,
                databaseMapping.Model.Namespaces
                .Single().ComplexTypes.Single()
                .Properties.Single(p => p.Name == "OrderQty")
                .Annotations.Single(a => a.Name == "StoreGeneratedPattern").Value);
        }