我在stackoverflow上遇到了一些与我的here类似的问题,但它们看起来并没有深入到连接表中,而且我看不到任何适用于我的代码的东西,所以我希望有人可以查看我的代码位并告诉我为什么我得到
LINQ to Entities 不支持指定的类型成员“Locale_Section”。仅支持初始化程序、实体成员和实体导航属性。
private object SetNavItems(string Category, byte CultureID)
{
using (var db = new Compleate())
{
return (from n in db.Navigation
where n.Category == Category && n.Section.Locale_Section.CultureID == CultureID
orderby n.Position
select new
{
n.Section.Locale_Section.Title,
n.Section.LinkAddress
}).ToList();
}
}
导航.cs
[Table("Navigation")]
public class Navigation
{
[Key, Required, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int NavigationID { get; set; }
[Required, MaxLength(16), Column(TypeName = "varchar")]
public string Category { get; set; }
[Required]
public Int16 SectionID { get; set; }
[ForeignKey("SectionID")]
public virtual Section Section { get; set; }
[Required]
public byte Position { get; set; }
}
截面.cs
[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; }
[NotMapped]
public string LinkAddress
{
get
{
return Type + "/" + RouteName;
}
}
[NotMapped]
public virtual Locale_Section Locale_Section { get; set; }
}
Locale_Section.cs
[Table("Locale_Section")]
public class Locale_Section
{
[Key, Required, Column(Order = 0)]
public Int16 SectionID { get; set; }
[ForeignKey("SectionID")]
public virtual Section Section { get; set; }
[Key, Required, Column(Order = 1)]
public byte CultureID { get; set; }
[ForeignKey("CultureID")]
public virtual Culture Culture { get; set; }
[Required, MaxLength(250)]
public string Title { get; set; }
public string Synopsis { get; set; }
}