3
I am editing a column of the database and so far everything goes very well, but when I load the table that contains this column using Include, simply does not update the "Chauffeur", exchange the ID in the relationship but in the listing continues the name of the old registered (actually what was registered never exchange).
Follow the consultation:
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 shows how the driver is not actually being loaded properly:
Follow the reference code 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);