title: Can I map an EF entity to two tables with a polymorphic foreign key?
body: <p>I would like to make a new, mapped entity that looks like this:</p>
  
  <pre><code>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
  }
  </code></pre>
  
  <p>The problem is that <code>Path</code> is in a different table than the other items and one of those tables has a polymorphic foreign key.  Here are my tables:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Microsoft has HOWTOs on mapping entities to two tables (<a href="http://msdn.microsoft.com/en-us/library/cc716698.aspx" rel="nofollow">here</a> and <a href="http://msdn.microsoft.com/en-us/library/bb896233.aspx" rel="nofollow">here</a>), but they seem to rely on a normal foreign key.</p>
  
  <p>Is there some way to map <code>Paths.ItemId</code> to <code>Items.Id</code> and then hardcode a value for <code>Paths.ItemType</code> in the join?</p>