I have two entities which have one to one relationship:
public class User
{
[Key]
public int Id { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
public string CarId { get; set; }
public Car Car{ get; set; }
}
and
public class Car
{
[Key]
public int Id { get; set; }
[Required]
public string PlateNumber{ get; set; }
[Required]
public string Description { get; set; }
public int UserId { get; set; }
public User User { get; set; }
}
Let say I have User with Id 1 which is related to Car with Id 5 (I have 5 cars already inserted into the table "Cars"). Is it possible to modify existing relation of User to Car(1->5) with another car(car with Id 2 for instance and become 1->2) using EF Core and if yes can you give me an example?