Skip to content

Commit

Permalink
Add owned entity types support to more places in query
Browse files Browse the repository at this point in the history
Record the EntityType when visiting existing JoinClause
Update QuerySourceMapping when cloning
Add provider-specific model building extensions
Add more query tests for owned entity types
  • Loading branch information
AndriySvyryd committed Apr 21, 2017
1 parent 1c8eeb1 commit c52548b
Show file tree
Hide file tree
Showing 41 changed files with 2,380 additions and 597 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ public virtual string TableName
return (string)Annotations.GetAnnotation(
RelationalFullAnnotationNames.Instance.TableName,
ProviderFullAnnotationNames?.TableName)
?? EntityType.ShortName();
?? GetDefaultTableName();
}
[param: CanBeNull] set { SetTableName(value); }
}

private string GetDefaultTableName()
=> EntityType.HasDelegatedIdentity()
? $"{GetAnnotations(EntityType.DefiningEntityType).TableName}_{EntityType.DefiningNavigationName}"
: EntityType.ShortName();

protected virtual bool SetTableName([CanBeNull] string value)
=> Annotations.SetAnnotation(
RelationalFullAnnotationNames.Instance.TableName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Specification.Tests.TestModels.ComplexNavigationsModel;

namespace Microsoft.EntityFrameworkCore.Specification.Tests
{
public abstract class ComplexNavigationsOwnedQueryFixtureBase<TTestStore> : ComplexNavigationsQueryFixtureBase<TTestStore>
where TTestStore : TestStore
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Level1>().Property(e => e.Id).ValueGeneratedNever();

modelBuilder.Entity<Level1>()
.Ignore(e => e.OneToOne_Optional_Self)
.Ignore(e => e.OneToMany_Required_Self)
.Ignore(e => e.OneToMany_Required_Self_Inverse)
.Ignore(e => e.OneToMany_Optional_Self)
.Ignore(e => e.OneToMany_Optional_Self_Inverse)
.Ignore(e => e.OneToMany_Required)
.Ignore(e => e.OneToMany_Optional)
.OwnsOne(e => e.OneToOne_Required_PK, Configure);

modelBuilder.Entity<ComplexNavigationField>().HasKey(e => e.Name);
modelBuilder.Entity<ComplexNavigationString>().HasKey(e => e.DefaultText);
modelBuilder.Entity<ComplexNavigationGlobalization>().HasKey(e => e.Text);
modelBuilder.Entity<ComplexNavigationLanguage>().HasKey(e => e.Name);

modelBuilder.Entity<ComplexNavigationField>().HasOne(f => f.Label);
modelBuilder.Entity<ComplexNavigationField>().HasOne(f => f.Placeholder);

modelBuilder.Entity<ComplexNavigationString>().HasMany(m => m.Globalizations);

modelBuilder.Entity<ComplexNavigationGlobalization>().HasOne(g => g.Language);
}

protected virtual void Configure(ReferenceOwnershipBuilder<Level1, Level2> l2)
{
l2.Ignore(e => e.OneToOne_Optional_Self)
.Ignore(e => e.OneToMany_Required_Self)
.Ignore(e => e.OneToMany_Required_Self_Inverse)
.Ignore(e => e.OneToMany_Optional_Self)
.Ignore(e => e.OneToMany_Optional_Self_Inverse)
.Ignore(e => e.OneToMany_Required)
.Ignore(e => e.OneToMany_Required_Inverse)
.Ignore(e => e.OneToMany_Optional)
.Ignore(e => e.OneToMany_Optional_Inverse);

l2.HasForeignKey(e => e.Id)
.OnDelete(DeleteBehavior.Restrict);

l2.Property(e => e.Id).ValueGeneratedNever();

l2.HasOne(e => e.OneToOne_Required_PK_Inverse)
.WithOne(e => e.OneToOne_Required_PK);

l2.HasOne(e => e.OneToOne_Optional_PK_Inverse)
.WithOne(e => e.OneToOne_Optional_PK)
.HasPrincipalKey<Level1>(e => e.Id)
.IsRequired(false);

l2.HasOne(e => e.OneToOne_Required_FK_Inverse)
.WithOne(e => e.OneToOne_Required_FK)
.HasForeignKey<Level2>(e => e.Level1_Required_Id)
.IsRequired()
.OnDelete(DeleteBehavior.Restrict);

l2.HasOne(e => e.OneToOne_Optional_FK_Inverse)
.WithOne(e => e.OneToOne_Optional_FK)
.HasForeignKey<Level2>(e => e.Level1_Optional_Id)
.IsRequired(false);

l2.OwnsOne(e => e.OneToOne_Required_PK, Configure);
}

protected virtual void Configure(ReferenceOwnershipBuilder<Level2, Level3> l3)
{
l3.Ignore(e => e.OneToOne_Optional_Self)
.Ignore(e => e.OneToMany_Required_Self)
.Ignore(e => e.OneToMany_Required_Self_Inverse)
.Ignore(e => e.OneToMany_Optional_Self)
.Ignore(e => e.OneToMany_Optional_Self_Inverse)
.Ignore(e => e.OneToMany_Required)
.Ignore(e => e.OneToMany_Required_Inverse)
.Ignore(e => e.OneToMany_Optional)
.Ignore(e => e.OneToMany_Optional_Inverse);

l3.HasForeignKey(e => e.Id)
.OnDelete(DeleteBehavior.Restrict);

l3.Property(e => e.Id).ValueGeneratedNever();

l3.HasOne(e => e.OneToOne_Required_PK_Inverse)
.WithOne(e => e.OneToOne_Required_PK);

l3.HasOne(e => e.OneToOne_Optional_PK_Inverse)
.WithOne(e => e.OneToOne_Optional_PK)
.HasPrincipalKey<Level2>(e => e.Id)
.IsRequired(false);

l3.HasOne(e => e.OneToOne_Required_FK_Inverse)
.WithOne(e => e.OneToOne_Required_FK)
.HasForeignKey<Level3>(e => e.Level2_Required_Id)
.IsRequired()
.OnDelete(DeleteBehavior.Restrict);

l3.HasOne(e => e.OneToOne_Optional_FK_Inverse)
.WithOne(e => e.OneToOne_Optional_FK)
.HasForeignKey<Level3>(e => e.Level2_Optional_Id)
.IsRequired(false);

l3.OwnsOne(e => e.OneToOne_Required_PK, Configure);
}

protected virtual void Configure(ReferenceOwnershipBuilder<Level3, Level4> l4)
{
l4.Ignore(e => e.OneToOne_Optional_Self)
.Ignore(e => e.OneToMany_Required_Self)
.Ignore(e => e.OneToMany_Required_Self_Inverse)
.Ignore(e => e.OneToMany_Optional_Self)
.Ignore(e => e.OneToMany_Optional_Self_Inverse)
.Ignore(e => e.OneToMany_Required_Inverse)
.Ignore(e => e.OneToMany_Optional_Inverse);

l4.HasForeignKey(e => e.Id)
.OnDelete(DeleteBehavior.Restrict);

l4.Property(e => e.Id).ValueGeneratedNever();

l4.HasOne(e => e.OneToOne_Required_PK_Inverse)
.WithOne(e => e.OneToOne_Required_PK);

l4.HasOne(e => e.OneToOne_Optional_PK_Inverse)
.WithOne(e => e.OneToOne_Optional_PK)
.HasPrincipalKey<Level3>()
.IsRequired(false);

l4.HasOne(e => e.OneToOne_Required_FK_Inverse)
.WithOne(e => e.OneToOne_Required_FK)
.HasForeignKey<Level4>(e => e.Level3_Required_Id)
.IsRequired()
.OnDelete(DeleteBehavior.Restrict);

l4.HasOne(e => e.OneToOne_Optional_FK_Inverse)
.WithOne(e => e.OneToOne_Optional_FK)
.HasForeignKey<Level4>(e => e.Level3_Optional_Id)
.IsRequired(false);
}
}
}
Loading

0 comments on commit c52548b

Please sign in to comment.