I trying to figure out how to use .Include() when selecting from abstract type to include relation entities of Implemented type, here is an example of what am I trying to do:
[Table("Comments")]
public abstract class Comment
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int CommentId { get; set; }
public int UserId { get; set; }
public virtual UserProfile User { get; set; }
public string Content { get; set; }
}
[Table("PostComments")]
public class PostComment : Comment
{
public int PostId { get; set; }
public virtual Post Post { get; set; }
}
[Table("UserProfiles")]
public class UserProfile
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
[MaxLength(200)]
public string UserName { get; set; }
public ICollection<Comments> Comments { get; set; }
}
using (DataContext db = new DataContext())
{
return db.UserProfiles.Include(x => x.Comments)
.Single(u => u.UserId == WebSecurity.CurrentUserId);
// Here I need a way to include Comment.Post if Comment
// is PostComment or some other child entity if Comment is
// from another inherited type
}