public virtual void Can_configure_one_to_one_relationship_from_an_owned_type(TestModelBuilder modelBuilder) { var model = modelBuilder.Model; modelBuilder.Ignore<Customer>(); modelBuilder.Entity<OtherCustomer>().OwnsOne(c => c.Details) .HasOne<SpecialCustomer>() .WithOne() .HasPrincipalKey<SpecialCustomer>(); Assert.NotNull(model.FindEntityType(typeof(CustomerDetails))); modelBuilder.Entity<SpecialCustomer>().OwnsOne(c => c.Details); modelBuilder.Validate(); var ownership = model.FindEntityType(typeof(OtherCustomer)).FindNavigation(nameof(Customer.Details)).ForeignKey; var foreignKey = model.FindEntityType(typeof(SpecialCustomer)).GetReferencingForeignKeys() .Single(fk => fk.DeclaringEntityType.ClrType == typeof(CustomerDetails) && fk.PrincipalToDependent == null); Assert.Same(ownership.DeclaringEntityType, foreignKey.DeclaringEntityType); Assert.NotEqual(ownership.Properties.Single().Name, foreignKey.Properties.Single().Name); Assert.Equal(2, model.GetEntityTypes().Count(e => e.ClrType == typeof(CustomerDetails))); Assert.Equal(2, ownership.DeclaringEntityType.GetForeignKeys().Count()); }
public virtual void Weak_types_with_FK_to_another_entity_works(TestModelBuilder modelBuilder) { var ownerEntityTypeBuilder = modelBuilder.Entity <BillingOwner>(); ownerEntityTypeBuilder.OwnsOne(e => e.Bill1, o => o.HasOne <Country>().WithMany().HasPrincipalKey(c => c.Name).HasForeignKey(d => d.Country)); ownerEntityTypeBuilder.OwnsOne(e => e.Bill2, o => o.HasOne <Country>().WithMany().HasPrincipalKey(c => c.Name).HasForeignKey(d => d.Country)); modelBuilder.Validate(); }