title: Entity Framework How mapping with condition?
body: <p>I have three class Student,Teacher and Document. Student and Teacher may have many Documents</p>
  
  <pre><code>public class BaseEntity
  {
      public int ItemId { get; set; }
  
      public bool IsDeleted { get; set; }
  } 
  
  //ParentType Student = 1
  public class Student : BaseEntity
  {
      public string Name { get; set; }
      public string Surname { get; set; }
  
      public ICollection&lt;Document&gt; Documents { get; set; }
  
  }
  
  //ParentType Teacher = 2
  public class Teacher : BaseEntity
  {
      public string Name { get; set; }
      public string Surname { get; set; }
  
      public ICollection&lt;Document&gt; Documents { get; set; }
  }
  
  public class Document
  {
      public int ParentId { get; set; } //Foreign Key
      public int ParentTypeId { get; set; }
  }
  </code></pre>
  
  <p>I use Entity Framework(Fluent API). For example, I create map for Student and I don't know how to configure Document in student with two Condition <code>(where parentId = itemId and ParentType = 1)</code>?</p>
  
  <pre><code>public class StudentMap : EntityTypeConfiguration&lt;Student&gt;
  {
      public StudentMap()
      {
          ToTable("Student", "dbo");
  
          // Primary Key
          HasKey(t =&gt; new {t.ItemId});
  
          // Properties
          Property(t =&gt; t.ItemId).HasColumnName("ItemId");
  
          Property(t =&gt; t.IsDeleted)
              .IsRequired()
              .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)
              .HasColumnName("IsDeleted");
  
          Property(t =&gt; t.Name)
              .IsRequired()
              .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)
              .HasColumnName("Name");
  
          Property(t =&gt; t.Surname)
              .IsRequired()
              .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)
              .HasColumnName("Surname");
      }
  </code></pre>