Пример #1
0
        public void GetMethodChain_returns_chan_when_required_to_many()
        {
            var modelBuilder = new DbModelBuilder();

            modelBuilder.Entity <Entity1>().HasRequired(e => e.Entity2).WithMany(e => e.Entity1s);
            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 == "Entity2");
            var otherEntityType         = model.ConceptualModel.EntityTypes.First(t => t.Name == "Entity2");
            var otherNavigationProperty = otherEntityType.NavigationProperties.First(p => p.Name == "Entity1s");

            var configuration = new MultiplicityConfiguration
            {
                LeftEntityType          = entityType,
                LeftNavigationProperty  = navigationProperty,
                RightNavigationProperty = otherNavigationProperty
            };
            var code = new CSharpCodeHelper();

            Assert.Equal(
                @".Entity<Entity1>()
                .HasRequired(e => e.Entity2)
                .WithMany(e => e.Entity1s)",
                configuration.GetMethodChain(code));
        }
        public void GetMethodChain_returns_chan_when_many_to_many()
        {
            var modelBuilder = new DbModelBuilder();
            modelBuilder.Entity<Entity1>().HasMany(e => e.Entity2s).WithMany(e => e.Entity1s);
            modelBuilder.Entity<Entity1>().Ignore(e => e.Entity2);
            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 == "Entity2s");
            var otherEntityType = model.ConceptualModel.EntityTypes.First(t => t.Name == "Entity2");
            var otherNavigationProperty = otherEntityType.NavigationProperties.First(p => p.Name == "Entity1s");

            var configuration = new MultiplicityConfiguration
                {
                    LeftEntityType = entityType,
                    LeftNavigationProperty = navigationProperty,
                    RightNavigationProperty = otherNavigationProperty
                };
            var code = new CSharpCodeHelper();

            Assert.Equal(
                @".Entity<Entity1>()
                .HasMany(e => e.Entity2s)
                .WithMany(e => e.Entity1s)",
                configuration.GetMethodChain(code));
        }