2011-08-09 116 views
0

我有一個表與這些列加載POCO部分

Id as integer 
Name as string 
Image as byte() 

然後我做了兩個POCO

Public Class TableBase 
    Id as Integer 
    Name as String 
End Class 

Public Class Table 
    Inherts TableBase 
    Image as byte() 
End Class. 

因爲我並不總是我需要加載圖像。 問題是我收到一個歧視錯誤,並且TPH的東西的解決方案不能解決它。因爲我無法在數據庫表中添加歧視列。

... 
    modelBuilder.Entity<Table>() 
    .Map(mc => mc.Requires("TableType").HasValue("Base")) 
    ... 

其實我沒有層次結構問題;我只需要部分加載POCO

問候!

回答

0

您不需要TPH,因爲在TPH中,數據庫中的記錄只能由一個實體類型表示 - 這意味着它可以是TableBaseTable,但兩者都不會。您需要table splitting

+0

其實經過大量的閱讀我認爲你是對的,最好的解決辦法是表分裂。這對我來說意味着不便,因爲我的Razor Views是在運行時用Reflection創建的。 順便說一下,我會離開繼承我的POCO :( – neo