2012-03-17 83 views
1

我得到一个错误 - 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);

我该如何解决这个错误?

+2

只是你知道,正确的拼写是[调色板](http://dictionary.reference.com/browse/palette)... – Timwi 2012-03-17 22:27:23

+0

@Timwi - 修正:) – 2012-03-17 22:33:07

回答

3

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

鉴于更新做只是

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

应该努力 - 如果要查询的Pallete实体。

+0

包含参考实际上是嵌套的,我会提供一个更详细的例子。 – 2012-03-17 22:17:43

+0

谢谢,你是对的。那确实包括了这个对象。 – 2012-03-17 22:33:53

+0

为什么只包括颜色不起作用(假设涂料有多个其他领域)? – 2012-03-17 22:42:16