指定的Include路径无效

本文关键字:路径 无效 Include | 更新日期: 2023-09-27 18:28:04

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

如何修复此错误?

指定的Include路径无效

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

考虑到更新只做

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

如果您正在查询Pallete实体,则应该可以工作。