EF6 insert of parent and child
<p>in EF6 the parent inserted but its child not saved and give error </p>

<pre><code>public virtual void Insert(TEntity entity)
        {

            entity.ObjectState = ObjectState.Added;

            _dbSet.Attach(entity);
            context.Entry(entity).State = EntityState.Added;
        }
</code></pre>

<p>but it give error : </p>

<p>A referential integrity constraint violation occurred: The property value(s) of  n one end of a relationship do not match the property value(s) of n the other end</p>

<p>the models looks like </p>

<pre><code>public class student 
{
public int Id;
virtual ICollection&lt;Courses&gt; Courseslist ;
}
</code></pre>