I have a code first application which defined like this:
public abstract class Entity
{
[Key]
public int Id { get; set; }
public DateTime CreatedOn { get; set; }
}
public class Post : Entity
{
public string Text { get; set; }
public virtual ICollection<UserObject> Likes { get; set; }
}
public class Blog : Post
{
public string Title { get; set; }
public string Content { get; set; }
}
public class Comment : Post
{
public string Content { get; set; }
public virtual Post Parent { get; set; }
}
public class UserObject : Entity
{
public string Username { get; set; }
public string Login { get; set; }
}
public class Profile : UserObject
{
public DateTime DoB { get; set; }
public string Avatar { get; set; }
public ICollection<Blog> Blogs { get; set; }
}
The idea is: A profile can have many blogs, a post (blog or comment) can have many likes. I want something like this on database:
Table Posts
Id
...
Table Profiles
Id
...
Table PostLikes
Id
PostId
UserId
Table ProfileBlogs
Id
UserId
BlogId
I tried but can't get Fluent API to generate these schemes. I tried with many-to-many relations, but because my data structure has inheritances, so it does not work.
How to do this in Fluent API?