7
下面是我用来尝试并包含User
表的Lambda表达式,该表引发错误。包含派生模型相关类
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();
include语句给出了这样的错误
包含路径表达式必须是指在 所述类型定义的导航属性。对于参考导航属性使用虚线路径,对集合导航属性使用Select 运算符。
有问题的模型
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; }
}
怎样包括User
表Cover
型ProjectDoc
?
UPDATE: 根据答案。我更新了Cover
的模型,看起来像这样,并删除了我说的导致错误的内容。我现在可以得到的数据:
public class Cover : ProjectDoc
{
public string CoverURL { get; set; }
public int UserID { get; set; }
public virtual User User { get; set; }
}