【发布时间】:2011-01-25 19:33:59
【问题描述】:
我想创建一个新的映射实体,如下所示:
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 有关于将实体映射到两个表(here 和 here)的 HOWTO,但它们似乎依赖于普通的外键。
有没有办法将Paths.ItemId 映射到Items.Id,然后在连接中硬编码Paths.ItemType 的值?
【问题讨论】:
标签: .net entity-framework entity-framework-4 polymorphic-associations edmx