1

I'm sharing one entity between other entities with selector property. Code First codes are :

public enum ContentTypes : byte
{
    EntityA = 0,
    EntityB = 1
}

public class SharedContent
{
    public int Id { get; set; }
    public ContentTypes ContentType { get; set; }

    public string Name { get; set; }
    public string Description { get; set; }
}

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

    [ForeignKey("ContentId")]
    public virtual SharedContent Content { get; set; }
    public int ContentId { get; set; }
}

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

    [ForeignKey("ContentId")]
    public virtual SharedContent Content { get; set; }
    public int ContentId { get; set; }
}

After executing below codes to get entityA from database entity framework fills all properties except entityA.Content! Whats wrong? What I need to get entityA with Content property?

var entityA = context.EntityA.Include(e => e.Content).ToList();
gDir
  • 35
  • 1
  • 6

1 Answers1

0

My mistake! In original code I'm creating content in constructor. For detailed explanation follow the link...

EF codefirst : whether initialize navigation properties?

Community
  • 1
  • 1
gDir
  • 35
  • 1
  • 6