指定的包含路径无效

时间:2012-03-17 22:14:02

标签: c# entity-framework include ef-code-first

使用.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);

如何解决此错误?

1 个答案:

答案 0 :(得分:4)

Color是一个字符串属性 - 您不需要Include,因为Color没有引用单独的实体。

鉴于更新只是

query = query.Include(pal => pal.Paint);

应该有效 - 如果您要查询Pallete个实体。

相关问题