© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
16 replies
antimatter8189

❔ Ef core creating shadow foreign key, why?

Got this error:
The foreign key property 'LessonPhase.LessonId1' was created in shadow state because a conflicting property with the simple name 'LessonId' exists in the entity type, but is either not mapped, is already used for another relationship, or is incompatible with the associated primary key type
The foreign key property 'LessonPhase.LessonId1' was created in shadow state because a conflicting property with the simple name 'LessonId' exists in the entity type, but is either not mapped, is already used for another relationship, or is incompatible with the associated primary key type

The classes:
public class LessonPhase : Entity<Guid>, ISoftDelete
{
    public required int PhaseNumber { get; init; }
    public int NumberOfExplanationRequestsMade { get; set; }
    public Lesson Lesson { get; init; }
    public Guid LessonId { get; init; }
    public bool IsDeleted { get; set; }
public class LessonPhase : Entity<Guid>, ISoftDelete
{
    public required int PhaseNumber { get; init; }
    public int NumberOfExplanationRequestsMade { get; set; }
    public Lesson Lesson { get; init; }
    public Guid LessonId { get; init; }
    public bool IsDeleted { get; set; }

public class Lesson : FullAuditedAggregateRootWithUser<Guid, IdentityUser>
{
    public required string LessonSrcLanguage { get; init; }
    public required string LessonDstLanguage { get; init; }
    public int LessonNumber { get; set; }
    public int LessonDifficulty { get; init; }
    public required LessonState LessonState { get; set; }
    public ICollection<LessonPhase> Phases { get; set; }
    public LessonPhase CurrentPhase { get; set; }

    public Lesson()
    {
        Phases = new Collection<LessonPhase>();
    }
}
public class Lesson : FullAuditedAggregateRootWithUser<Guid, IdentityUser>
{
    public required string LessonSrcLanguage { get; init; }
    public required string LessonDstLanguage { get; init; }
    public int LessonNumber { get; set; }
    public int LessonDifficulty { get; init; }
    public required LessonState LessonState { get; set; }
    public ICollection<LessonPhase> Phases { get; set; }
    public LessonPhase CurrentPhase { get; set; }

    public Lesson()
    {
        Phases = new Collection<LessonPhase>();
    }
}

Mapping:
  builder.Entity<Lesson>(b =>
        {
            b.ToTable(lingumindConsts.DbTablePrefix + "Lessons", lingumindConsts.DbSchema);
            b.ConfigureByConvention(); //auto configure for the base class props
        });

        builder.Entity<LessonPhase>(b =>
        {
            b.ToTable(lingumindConsts.DbTablePrefix + "Phases", lingumindConsts.DbSchema);
            b.HasOne(x => x.Lesson).WithMany(x => x.Phases).HasForeignKey(x => x.LessonId);
  builder.Entity<Lesson>(b =>
        {
            b.ToTable(lingumindConsts.DbTablePrefix + "Lessons", lingumindConsts.DbSchema);
            b.ConfigureByConvention(); //auto configure for the base class props
        });

        builder.Entity<LessonPhase>(b =>
        {
            b.ToTable(lingumindConsts.DbTablePrefix + "Phases", lingumindConsts.DbSchema);
            b.HasOne(x => x.Lesson).WithMany(x => x.Phases).HasForeignKey(x => x.LessonId);


Any idea? Cant seem to resolve this
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ ef core foreign key problem
C#CC# / help
4y ago
EF Core Nullable Foreign Key Relationship
C#CC# / help
7mo ago
✅ Setting Foreign key as Primary Key (EF Core)
C#CC# / help
2y ago
Foreign Key between Models with ef
C#CC# / help
3y ago