我不知道如何访问标记为 NotMapped 的属性,以便我可以打印它。当我尝试访问它时,我得到
LINQ to Entities 不支持指定的类型成员“LinkAddress”。仅支持初始化程序、实体成员和实体导航属性。
我的 LINQ 查询是:
(from n in db.Navigation
join s in db.Sections on n.SectionID equals s.SectionID
join sl in db.Locale_Sections on s.SectionID equals sl.SectionID
where n.Category == "Books" && sl.CultureID == 1
select new
{
s.LinkAddress,
sl.Title,
}).ToList();
我对 Section 的上下文是:
[Table("Section")]
public class Section
{
[Key, Required, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Int16 SectionID { get; set; }
public Int64 LogoFileID { get; set; }
[ForeignKey("LogoFileID")]
public virtual File File { get; set; }
[Required, MaxLength(15), Column(TypeName = "varchar")]
public string RouteName { get; set; }
[Required, MaxLength(15), Column(TypeName = "varchar")]
public string Type { get; set; }
public virtual ICollection<Locale_Section> Translations { get; set; }
[NotMapped]
public string LinkAddress
{
get
{
return Type + "/" + RouteName;
}
}
}