Exemplo n.º 1
0
        public void Discover_returns_configuration_when_fk_equals_entity_plus_pk_but_more_than_one_association()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity <Entity1>().HasRequired(e => e.Two).WithMany().HasForeignKey(e => e.Entity2Entity2Id);
            var model              = modelBuilder.Build(new DbProviderInfo("System.Data.SqlClient", "2012"));
            var entityType         = model.ConceptualModel.EntityTypes.First(t => t.Name == "Entity1");
            var navigationProperty = entityType.NavigationProperties.First(p => p.Name == "Two");

            var configuration = new ForeignKeyDiscoverer()
                                .Discover(navigationProperty, model) as ForeignKeyConfiguration;

            Assert.NotNull(configuration);
            Assert.Equal(new[] { "Entity2Entity2Id" }, configuration.Properties.Select(p => p.Name));
        }
Exemplo n.º 2
0
        public void Discover_returns_configuration_when_composite_key()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity <Entity2>().HasKey(e => new { e.Entity2Id, e.Name });
            modelBuilder.Entity <Entity1>().HasRequired(e => e.Two).WithMany().HasForeignKey(
                e => new { e.Entity2Id, e.Name });
            modelBuilder.Entity <Entity1>().Ignore(e => e.Entity2s);
            var model              = modelBuilder.Build(new DbProviderInfo("System.Data.SqlClient", "2012"));
            var entityType         = model.ConceptualModel.EntityTypes.First(t => t.Name == "Entity1");
            var navigationProperty = entityType.NavigationProperties.First(p => p.Name == "Two");

            var configuration = new ForeignKeyDiscoverer()
                                .Discover(navigationProperty, model) as ForeignKeyConfiguration;

            Assert.NotNull(configuration);
            Assert.Equal(new[] { "Entity2Id", "Name" }, configuration.Properties.Select(p => p.Name));
        }
        public void Discover_returns_configuration_when_fk_equals_entity_plus_pk_but_more_than_one_association()
        {
            var modelBuilder = new DbModelBuilder();
            modelBuilder.Entity<Entity1>().HasRequired(e => e.Two).WithMany().HasForeignKey(e => e.Entity2Entity2Id);
            var model = modelBuilder.Build(new DbProviderInfo("System.Data.SqlClient", "2012"));
            var entityType = model.ConceptualModel.EntityTypes.First(t => t.Name == "Entity1");
            var navigationProperty = entityType.NavigationProperties.First(p => p.Name == "Two");

            var configuration = new ForeignKeyDiscoverer()
                .Discover(navigationProperty, model) as ForeignKeyConfiguration;

            Assert.NotNull(configuration);
            Assert.Equal(new[] { "Entity2Entity2Id" }, configuration.Properties.Select(p => p.Name));
        }
        public void Discover_returns_configuration_when_composite_key()
        {
            var modelBuilder = new DbModelBuilder();
            modelBuilder.Entity<Entity2>().HasKey(e => new { e.Entity2Id, e.Name });
            modelBuilder.Entity<Entity1>().HasRequired(e => e.Two).WithMany().HasForeignKey(
                e => new { e.Entity2Id, e.Name });
            modelBuilder.Entity<Entity1>().Ignore(e => e.Entity2s);
            var model = modelBuilder.Build(new DbProviderInfo("System.Data.SqlClient", "2012"));
            var entityType = model.ConceptualModel.EntityTypes.First(t => t.Name == "Entity1");
            var navigationProperty = entityType.NavigationProperties.First(p => p.Name == "Two");

            var configuration = new ForeignKeyDiscoverer()
                .Discover(navigationProperty, model) as ForeignKeyConfiguration;

            Assert.NotNull(configuration);
            Assert.Equal(new[] { "Entity2Id", "Name" }, configuration.Properties.Select(p => p.Name));
        }