我想做一个新的映射实体,如下所示:
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)
Microsoft 有关于将实体映射到两个表(此处和此处)的 HOWTO,但它们似乎依赖于普通的外键。
是否有某种方法可以映射Paths.ItemId
到连接中Items.Id
的值,然后对其进行硬编码Paths.ItemType
?