使用.Include - A specified Include path is not valid. The EntityType 'myProject.DAL.Paint' does not declare a navigation property with the name 'Color'.
DAL
public DBSet<Palete> Paletes {get; set; }
public DbSet<Paint> Paints { get; set; }
(注意:modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
)
模型
public class Palete
{
public virtual Paint Paint { get; set; }
}
public class Paint
{
public string Color { get; set; }
}
query = query.Include(pal => pal.Paint.Color);
如何解决此错误?
答案 0 :(得分:4)
Color
是一个字符串属性 - 您不需要Include
,因为Color
没有引用单独的实体。
鉴于更新只是
query = query.Include(pal => pal.Paint);
应该有效 - 如果您要查询Pallete
个实体。