public abstract class Base {
public Guid Id { get;set; }
public Navigation Nav { get;set; }
public string NavID { get;set; }
}
public class ConcreteFirst: Base { }
public class ConcreteSecond: Base { }
public class Navigation Nav {
public string NavID { get; set; }
public ICollection<ConcreteFirst> ConcreteFirsts { get;set; }
public ICollection<ConcreteSecond> ConcreteSeconds { get;set; }
}
//OnModelCreating
builder.Entity<Base>().Ignore(b => b.Nav);
builder.Entity<ConcreteFirst>()
.HasOne(c => c.Nav)
.WithMany(n => n.ConcreteFirsts)
.HasForeignKey(c => c.NavID);
builder.Entity<ConcreteSecond>()
.HasOne(c => c.Nav)
.WithMany(n => n.ConcreteSeconds)
.HasForeignKey(c => c.NavID);
//...
DbSet<Base> Bases { get; set;}
DbSet<ConcreteFirst> Firsts { get; set;}
DbSet<ConcreteSecond> Seconds { get; set;}
DbSet<Navigation> Navigations { get; set; }
There is error:
The foreign keys {NavID} on 'ConcreteSecond' and {'NavID'} on 'ConcreteFirst' are both mapped to FK_Bases_Navigations_NavID' but with different uniqueness
I guess it can be fixed of renaming either ConcreteFirst.Nav or ConcreteSecond.Nav property but it will cause of the increase of columns in Bases table. How can I resolve this issue with Nav name for both ConcreteFirst and ConcreteSecond?