Blogs { get; set; } = new List(); publi" /> Blogs { get; set; } = new List(); publi" /> Blogs { get; set; } = new List(); publi"/>

Add ChildEntityIds field in Entity Framework?

29 Views Asked by At

I have two entities:

class User
{
    [Column("id")]
    public string Id { get; set; }

    public IEnumerable<Blog> Blogs { get; set; } = new List<Blog>();
    public IEnumerable<string> BlogIds { get; set; } = new List<string>(); // <-- how to implement this?
}

class Blog
{
    [Column("id")]
    public string Id { get; set; }

    [Column("title")]
    public string Title { get; set; }
    
    [ForeignKey(nameof(Author))]
    public string AuthorId { get; set; }

    public User Author { get; set; }
}

I could solve this loading blogs with user and then using a getter, but there should be some more elegant solution.

0

There are 0 best solutions below