C# Entity Framework polymorphy in List

Viewed 36

I´ve got a Class Card, where every Card can have a List of BlockMessages and BlockMessage is abstract and implemented by different BlockMessages which should be saved as TPT. So far I´ve got this:

modelBuilder.Entity<DbBlockApplication>(app =>
{
   app.HasOne(x => x.Card as DbCard).WithMany(x => x.BlockMessages as List<DbBlockApplication>); // <-- This line isn´t working
   anfa.ToTable(nameof(DbBlockApplication);

   modelBuilder.Entity<DbFreeBlock>(app =>
   {
      app.HasOne(x => x.Card as DbCard).WithMany(x => x.BlockMessages as List<DbFreeBlock>); // <-- This line isn´t working
      anfa.ToTable(nameof(DbFreeBlock);
   });
}

Card has the following Property:

public interface IDbCard : IDbEntity
{ 
    List<IDbBlockMessage> BlockMessages { get; set; }
}

Now I want to archive that every BlockMessage has a Foreign-Key on Card and on Load the Card loads all BlockMessages into the field BlockMessages. Perfectly would be when the BlockMessages gonna load by Time Order.

0 Answers
Related