2

我想做一个新的映射实体,如下所示:

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

4

1 回答 1

3

一种方法是创建一个视图,其中包含您需要的列和 ItemType 上的过滤器。

然后将该视图添加到您的实体模型中。

于 2011-01-31T20:32:37.170 回答