InsertOrUpdateGraph 1 to 1

Jan 18 at 7:16 PM
Edited Jan 24 at 8:30 PM
Trying to insert graph.
public class Customer : DatabaseEntity
    public int Id { get; set; }
    public virtual CustomerUser CustomerUser { get; set; }

public class CustomerUser : DatabaseEntity
    public int CustomerUserId { get; set; }
    public virtual Customer Customer { get; set; }
customer.CustomerUser = customerUser
await _unitOfWorkAsync.SaveChangesAsync();

Get error:

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.CustomerUser_dbo.Customer_CustomerUserId". The conflict occurred in database "Ebpp", table "dbo.Customer", column 'Id'. The statement has been terminated.

What am I missing?
Jan 19 at 2:40 PM
Edited Jan 19 at 2:47 PM
Have you set identity?
public class Customer : DatabaseEntity
    public int Id { get; set; }
Is this value set to null during creation of object?
Your code seems to be look ok.
Jan 23 at 5:18 PM
Yes, identity is set. If I do this in two steps, insert the Customer, get the id and populate it to CustomerUser it works. Was trying to save a step.
Jan 24 at 8:29 PM
Got it to work by going this route
            using (var context = new Context())
                return Ok(customer);
Marked as answer by TheFinalSQL on 1/24/2017 at 12:29 PM