I have the following entities:
public class ApplicationUser : IdentityUser
{
...
public int? StudentId { get; set; }
public virtual Student Student { get; set; }
}
public class Student
{
public int Id { get; set; }
public string UserId { get; set; }
public virtual ApplicationUser User { get; set; }
}
And I'm trying to create an new application user and student, so I'm doing this:
var user = new ApplicationUser() {
Name = "test",
UserName = "test",
Student = new Student ()
};
var result = await userManager.CreateAsync(user, "test12345!");
Result is success, the two entities are inserted in database, but Student.UserId is null
How can I insert both entities and their relationship?
I tried setting student.UserId = user.Id, but then I get an exception with this message: "Unable to determine a valid ordering for dependent operations"