Entity Framework save collection
<p>I have Entity Framework Code First models. When I try save collection of Accounts in one insert i get error message.</p>

<pre><code> public class User
{
    [Key]
    public int Usr_Id { get; set; }
    [Required]
    [MaxLength(35)]
    public string Name { get; set; }
    [Required]
    [MaxLength(35)]
    public string Surname { get; set; }
    [Required]
    [MaxLength(35)]
    public string Location { get; set; }        

    //NAVIGATION
    public User()
    {
        UserDevices = new List&lt;UserDevice&gt;();
    }

    public virtual ICollection&lt;UserDevice&gt; UserDevices { get; set; }

}

 public class UserDevice
{
    [Key]
    public int UsrDev_Id { get; set; }
    [Required]
    [MaxLength(50)]
    public string PurposeOfUse { get; set; }

    // NAVIGATION

    public UserDevice()
    {
        Accounts = new List&lt;Account&gt;();
    }

    //User can have many UserDevice
    public int Usr_Id { get; set; }        
    public virtual User User { get; set; }

    //UserDevice can have many Acoount
    public virtual ICollection&lt;Account&gt; Accounts { get; set; }

    //One to one
    public virtual SoftwareInformation SoftwareInformation { get; set; }
    public virtual HardwareInformation HardwareInformation { get; set; }
}

 public class Account
{
    [Key]
    public int Acc_Id { get; set; }
    public string Name { get; set; }

    //NAVIGATION

    //UserDevice can have many Account
    public int UsrDev_Id { get; set; }
    public virtual UserDevice UserDevice { get; set; }

}
</code></pre>

<p>Insert of new UserDevice</p>

<pre><code>List&lt;Account&gt; accountsList = new List&lt;Account&gt;();

            foreach (var item in model.DeviceInformations.OS.Accounts)
            {
                accountsList.Add(new Account { Name = item.Name });
            }              


            _unitOfWork.UserDevices.Add(new UserDevice
            {
                Usr_Id = model.Usr_Id,
                PurposeOfUse = model.PurposeOfUse,

                HardwareInformation = new HardwareInformation
                {
                    MB_Manufacturer = model.DeviceInformations.Motherboard.Manufacturer,
                    MB_Model = model.DeviceInformations.Motherboard.Model,
                    MB_Name = model.DeviceInformations.Motherboard.Name,
                    MB_UUID = model.DeviceInformations.Motherboard.UUID,
                    CPU_Manufacturer = model.DeviceInformations.Processor.Manufacturer,
                    CPU_MaxClockSpeed = model.DeviceInformations.Processor.MaxClockSpeed,
                    CPU_Name = model.DeviceInformations.Processor.Name,
                },

                SoftwareInformation = new SoftwareInformation
                {
                    OS_Edition = model.DeviceInformations.OS.Edition,
                    OS_HostName = model.DeviceInformations.OS.HostName,
                    OS_Language = model.DeviceInformations.OS.Language,
                    OS_Platform = model.DeviceInformations.OS.Platform,
                    OS_ProductKey = model.DeviceInformations.OS.ProductKey,
                    OS_ServicePackVersion = model.DeviceInformations.OS.ServicePackVersion,
                    OS_Version = model.DeviceInformations.OS.Version
                }, 

                Accounts = accountsList
            });
            _unitOfWork.Commit();
</code></pre>

<p>Error message</p>

<blockquote>
  <p>{"Cannot insert the value NULL into column 'Acc_Id', table 'LICENSE_WATCHER_TEST.dbo.Accounts'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."}</p>
</blockquote>

<p>It happends when I try save Accout collection. Is there a way how to save Accouts collection in one Insert?</p>