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_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);
        }
Exemplo n.º 3
0
        public void External_duplicate_association_configuration()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Configurations
            .Add(new ProductCategoryConfiguration())
            .Add(new ProductSubcategoryConfiguration());

            modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);
        }
        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");
        }
Exemplo n.º 5
0
        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"));
        }
Exemplo n.º 6
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());
        }
Exemplo n.º 7
0
        public void Remove_an_existing_convention()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<Customer>();
            modelBuilder.Conventions.Remove<IdKeyDiscoveryConvention>();

            Assert.Throws<ModelValidationException>(
                () => modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo));
        }
Exemplo n.º 8
0
        public void Nested_config_class_with_private_property()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Configurations.Add(new CreditCard.CreditCardConfiguration());

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

            databaseMapping.Assert <CreditCard>().HasColumn("CardNumber");
        }
Exemplo n.º 9
0
        public void Add_custom_model_convention_with_ordering()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

            modelBuilder.Entity<CountryRegion>();
            modelBuilder.Conventions.AddAfter<IdKeyDiscoveryConvention>(new CodeKeyDiscoveryConvention());

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

            Assert.Equal(1, databaseMapping.EntityContainerMappings.Single().EntitySetMappings.Count());
        }
Exemplo n.º 10
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 = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            databaseMapping.Assert <StyledProduct>(s => s.Style).FacetEqual(150, f => f.MaxLength);
        }
        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 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_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);
        }
Exemplo n.º 14
0
        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");
        }
Exemplo n.º 15
0
        public void Build_model_with_dotted_table_name_and_dotted_schema_configured()
        {
            var modelBuilder = new AdventureWorksModelBuilder();

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

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

            Assert.True(databaseMapping.Database.GetEntitySets().Any(s => s.Schema == "sales.A.B"));
            Assert.True(databaseMapping.Database.GetEntitySets().Any(s => s.Schema == "dbo"));
        }
Exemplo n.º 16
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 = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            databaseMapping.Assert <TransactionHistory>(th => th.RowDetails);
        }
Exemplo n.º 17
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 = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            Assert.Equal(1, databaseMapping.EntityContainerMappings.Single().EntitySetMappings.Count());
            Assert.Equal(1, databaseMapping.Model.Namespaces.Single().ComplexTypes.Count);
        }
Exemplo n.º 18
0
        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);
        }
        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");
        }
        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);
        }
Exemplo n.º 21
0
        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"));
        }
Exemplo n.º 22
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 = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            Assert.Equal(2, databaseMapping.EntityContainerMappings.Single().EntitySetMappings.Count());
        }
Exemplo n.º 23
0
        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.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);
        }
Exemplo n.º 24
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 = 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");
        }
Exemplo n.º 25
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 = modelBuilder.BuildAndValidate(ProviderRegistry.Sql2008_ProviderInfo);

            databaseMapping.Assert <LargePhoto>(l => l.Photo)
            .FacetEqual(42, f => f.MaxLength)
            .DbEqual(42, f => f.MaxLength);
        }
        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_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 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);
        }
Exemplo n.º 29
0
        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.GetEntitySets().Any(s => s.Schema == "vendors"));
            Assert.True(databaseMapping.Database.GetEntitySets().Any(s => s.Schema == "details"));
        }