Exemplo n.º 1
0
        public void Can_set_relationship_overriding_annotations()
        {
            var modelBuilder = CreateConventionModelBuilder();

            modelBuilder.Entity <Owner>()
            .HasMany(e => e.Things)
            .HasRelationship("Mine")
            .WithOne(e => e.TheMan);

            var owner = modelBuilder
                        .Model
                        .FindEntityType(typeof(Owner));

            // Stuff will always be the declaring entity (note:
            // the direction of the foreign key can never be
            // inverted explicitly with the relation builders)
            var stuff = modelBuilder
                        .Model
                        .FindEntityType(typeof(Stuff));

            IForeignKey fk = stuff
                             .GetForeignKeys()
                             .First();

            Assert.Equal(stuff, fk.DeclaringEntityType);
            Assert.Equal(owner, fk.PrincipalEntityType);

            ICypherRelationship rel = fk
                                      .Cypher()
                                      .Relationship;

            Assert.Equal("Mine", rel.Relation.Name);
            Assert.Equal(owner, rel.Starting);
            Assert.Equal(stuff, rel.Ending);

            // Find the same relationships through the model
            rel = modelBuilder
                  .Model
                  .Starting(owner.ClrType)
                  .Single();

            Assert.Equal("Mine", rel.Relation.Name);
            Assert.Null(rel.Relation.ClrType);
            Assert.Equal(owner, rel.Starting);
            Assert.Equal(stuff, rel.Ending);
        }