Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata: Convention does not create relationship after Fluent API resolves ambiguity #8886

Closed
smitpatel opened this issue Jun 17, 2017 · 0 comments
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@smitpatel
Copy link
Contributor

public class Friendship
{
    public int Id { get; set; }

    public int ApplicationUserId { get; set; }
    public ApplicationUser ApplicationUser { get; set; }
}

public class ApplicationUser
{
    public int Id { get; set; }
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    // Configure model
    modelBuilder.Entity<Friendship>();
}

Above model works but below one fails

public class Friendship
{
    public int Id { get; set; }

    public int ActionUserId { get; set; }
    public ApplicationUser ActionUser { get; set; }

    public int ApplicationUserId { get; set; }
    public ApplicationUser ApplicationUser { get; set; }
}

public class ApplicationUser
{
    public int Id { get; set; }
    public IList<Friendship> Friendships { get; set; }
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    // Configure model
    modelBuilder.Entity<Friendship>().HasOne(e => e.ApplicationUser).WithMany(e => e.Friendships).HasForeignKey(e => e.ApplicationUserId);
}

Exception thrown:

Unable to determine the relationship represented by navigation property 'Friendship.ActionUser' of type 'ApplicationUser'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

The only difference between 2 models,
First one does not have ambiguity in relationship discovery. Second one has ambiguity but it is resolved by fluent API code but convention did not run correctly afterwards.

@smitpatel smitpatel changed the title Metadata: Metadata: Convention does not create relationship after Fluent API resolves ambiguity Jun 17, 2017
@ajcvickers ajcvickers added this to the 2.0.0 milestone Jun 19, 2017
@AndriySvyryd AndriySvyryd removed their assignment Jun 27, 2017
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

3 participants