2012-03-17 104 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