I am trying to insert object reference in my main object but EntityFramework will complain if I don\'t use its previously managed object. I simply want to avoid having a depende
if the same ApplicationUser has been previously loaded by the context, I get this error
So first check if the ApplicationUser
is loaded.
var newId = 2;
var newApplicationUser = db.ApplicationUsers.Local.FirstOrdefault(u => u.Id == newId)
?? new ApplicationUser { Id = newId };
myMovie.Owner = newApplicationUser;