I am editing a database column and so far everything is fine, but when I load the table that contains this column using Include, it simply does not update the " Driver ", ID in the relationship but in the listing continues the name of the old registered (actually the one that was registered never changes).
Follow the query:
return View(context.Veiculos.Include(v => v.Motorista).Where(v => v.EmpresaID == userId && !v.Excluido).OrderByDescending(c => c.Ano).ToList());
In the database the two columns of the listing are with the same driver, follow the print that proves:
Here'showthedriverisnotactuallybeingloadedcorrectly:
Follow the code of references between the two Models:
User Class:
[Display(Name = "Vehicles", ResourceType = typeof(Resources.Language))]
public virtual ICollection<Veiculo> VeiculosEmpresa { get; set; }
Vehicle Class:
[Required]
public Guid MotoristaID { get; set; }
[Display(Name = "Driver", ResourceType = typeof(Resources.Language))]
public virtual ApplicationUser Motorista { get; set; }
ModelBuilder:
modelBuilder.Entity<Veiculo>().HasRequired(x => x.Motorista).WithMany(x => x.VeiculosMotorista);
modelBuilder.Entity<Veiculo>().HasRequired(x => x.Empresa).WithMany(x => x.VeiculosEmpresa);