title: Multiplicity constraint violated. The role '' of the relationship '' has multiplicity 1 or 0..1
body: <p>I have a Tab object. This Tab object has many Questions. Here are my classes:</p>
  
  <pre><code>public abstract class Tab
  {
      /// &lt;summary&gt; init default values &lt;/summary&gt;
      public Tab()
      {
          // Do some init stuff
      }
      public int ID { get;set; }
  
      //...
  
      /// &lt;summary&gt; Question for this Tap. Like Quiz-App or Sweepstake &lt;/summary&gt;
      public virtual ICollection&lt;Tabs.Question&gt; Questions { get; set; }
  
      //...
  }
  
  public class Question
  {
      public int Id { get; set; }
      public int OrderNumber { get; set; }
      public string Text { get; set; }
  
      public virtual Tab Tab { get; set; }
   }
  </code></pre>
  
  <p>And here is the configuration for both classes.</p>
  
  <pre><code>class TabConfig : EntityTypeConfiguration&lt;Tab&gt;
  {
      public TabConfig()
      {
          this.Map(m =&gt; m.Requires("AppType").HasValue&lt;byte&gt;((byte)ApplicationType.Application)).ToTable("TmTabs");
          this.HasKey(c =&gt; c.ID);
          this.Property(p =&gt; p.ID).HasColumnName("ID").IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
  
      }
  }
  
  public class QuestionConfig : EntityTypeConfiguration&lt;Question&gt;
  {
      public QuestionConfig()
      {
          ToTable("TmQuestions");
          HasKey(q =&gt; q.Id);
          Property(q =&gt; q.Id).HasColumnName("Id").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
          Property(q =&gt; q.OrderNumber).HasColumnName("OrderNumber").IsRequired();
          Property(q =&gt; q.Text).HasColumnName("Text").IsRequired();
          HasRequired(q =&gt; q.Tab).WithMany(t =&gt; t.Questions).Map(q =&gt; q.MapKey("TmTabs_Id")).WillCascadeOnDelete(false);
      }
  }
  </code></pre>
  
  <p>And the configuration will be added to the built event like this.</p>
  
  <pre><code>public class ModelContext : DbContext
  {
  
      public Guid ContractId { get; set; }
  
      #region construction
  
      public ModelContext()
          : base(Tools.DatabaseTools.GetDefaultConnectionString())
      {
          ContractId = Guid.Empty;
      }
  
      public ModelContext(Guid contractGuid)
          : base(Tools.DatabaseTools.GetConnectionString(contractGuid))
      {
          ContractId = contractGuid;            
      }
  
      public ModelContext(string connectionString)
          : base(connectionString)
      {
          ContractId = Guid.Empty;
      }
  
      public ModelContext(string connectionString, Guid contractGuid)
          : base(connectionString)
      {
          ContractId = contractGuid;
      }
  
  
      public DbSet&lt;Tab&gt; Tabs { get; set; }     
      public DbSet&lt;Question&gt; Questions { get; set; }
  
  
      protected override void OnModelCreating(DbModelBuilder builder)
      {
          builder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;();
  
          // tab-table
          builder.Configurations.Add(new TabConfig());
  
  
          // Qustions
          builder.Configurations.Add(new ModelConfig.QuestionConfig());
  
  
          base.OnModelCreating(builder);
  
      }
  }
  </code></pre>
  
  <p>On my Edit-Form I bind the whole Tab object to a binding Source and I edit some property of the Tab object and I add Questions.</p>
  
  <p>If I save the Tab object the first time everything works fine. But if I edit the tab object I got this error:</p>
  
  <pre><code>Multiplicity constraint violated. The role 'Question_Tab_Target' of the relationship 'Tabmaker.Common.Question_Tab' has multiplicity 1 or 0..1.
  </code></pre>
  
  <p>The code for the Tab business layer is:</p>
  
  <pre><code>public bool SaveTab&lt;T&gt;(ModelContext context, T tab) where T:Tab
      {
          try
          {
              // add if detached
              if (tab.ID == 0)
              {
                  // new tab code
              }
  
  
              // attach/set to be modified if id!=0. if tab is not detached, the property 
              // changes were already tracked and nothing need to be done here
              var state = context.Entry(tab).State;
              if (state == EntityState.Detached || state == EntityState.Deleted)
              {
                  context.Entry(tab).State = EntityState.Modified;
              }
              context.SaveChanges();
              return true;
          }
          catch (Exception ex)
          {
              // Catch
      return false
          }
      }
  </code></pre>
  
  <p>The error occurs if I ask for the state of the tab-entity:</p>
  
  <pre><code>var state = context.Entry(tab).State;
  </code></pre>
  
  <p>I hope I explained everything as good as possible.</p>