Here's the Lambda expression that I use to try to include a User table that causes an error.
ICollection<Activity> activity = db.Activities .Include(i => i.Project.ProjectDoc.OfType<Cover>().Select(v => v.User)) .Where(u => u.UserID == WebSecurity.CurrentUserId) .OrderByDescending(d => d.DateCreated).ToList();
The include statement gives this error.
The Include path expression must specify a navigation property defined on the type. Use the dashed paths for reference navigational properties and the Select operator for navigational properties of the collection.
The model in question
public abstract class ProjectDoc { public int ProjectDocID { get; set; } public int ProjectID { get; set; } public string DocTitle { get; set; } public string Status { get; set; } public string Access { get; set; } public DateTime DateCreated { get; set; } public virtual ProjectDocAccess ProjectDocAccess { get; set; } public virtual Project Project { get; set; } public virtual ICollection<Comment> Comment { get; set; } public ICollection<ProjectDocVote> ProjectDocVote { get; set; } } public class Segment : ProjectDoc { public string Content { get; set; } } public class Cover : ProjectDoc { public string CoverURL { get; set; } public int UserID { get; set; } public User User { get; set; } }
How to include a User table for a ProjectDoc type Cover ?
UPDATE : For the answer. I updated the model for Cover to look like this and removed the include, which, as I said, caused an error. Now I can get the data:
public class Cover : ProjectDoc { public string CoverURL { get; set; } public int UserID { get; set; } public virtual User User { get; set; } }
Jed grant
source share