2
我想提出一個新的,映射實體,看起來像這樣:我可以將EF實體映射到具有多態外鍵的兩個表嗎?
public class PathedItem
{
public long Id { get; set; } // from the Items table
public string Name { get; set; } // from the Items table
public string Path { get; set; } // from the Paths table
}
的問題是,Path
是在不同的表比其他項目,這些表中的一個具有多態外鍵。這裏是我的表:
CREATE TABLE Items (
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](255) NOT NULL)
CREATE TABLE Paths (
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[Path] [nvarchar](255) NOT NULL,
[ItemId] [bigint] NOT NULL,
[ItemType] [int] NOT NULL)
微軟對映射實體兩個表(here和here)HOWTO文檔,但他們似乎依靠正常的外鍵。
有什麼方法可以將Paths.ItemId
映射到Items.Id
,然後在連接中硬編碼的值嗎?
這是一個不錯的主意,謝謝! – ladenedge 2011-02-03 14:56:51