I have a strange relation in my database.
Basically it's an entity connected to entities of the same type.
What I have is this:
Model:
public class Article
{
-- Properties --
ICollection<Article> ConnectedArticles { get; set; }
}
Fluent API:
modelBuilder.Entity<Article>()
.HasMany(ca => ca.ConnectedArticles)
.WithMany(ca => ca.ConnectedArticles)
.Map(m =>
{
m.MapLeftKey("ArtNo");
m.MapRightKey("ArtNo");
m.ToTable("ConnectedArticles");
});
This does not play well with Entity Framework and results in the error: The navigation property 'ConnectedArticles' declared on type 'ServiceSystem.Models.CommonArticle' cannot be the inverse of itself.
I could solve this issue by creating a new model which contains the related articles like so:
public class ConnectedArticle
{
public Article article1 { get; set; }
public Article article2 { get; set; }
}
But I'm hoping Entity Framework can do this on it's own, just like it does with many-to-many for separate entities.
Is it possible to solve this nicely with Entity Framework or am I missing something critical?
Thanks, Robin Dorbell