I have two models, configured in a one-to-one relationship:
public class PointOfInterestModel
{
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
public string Description { get; set; }
[Required]
public CoordinatesModel Coordinates { get; set; }
}
public class CoordinatesModel
{
[Key]
[ForeignKey("PointOfInterest")]
public int Id { get; set; }
[Required]
public float Longitude { get; set; }
[Required]
public float Latitude { get; set; }
public PointOfInterestModel PointOfInterest { get; set; }
}
So, they should exist in a one-to-one relationship. The PointOfInterestModel should only have one CoordinatesModel, and a CoordinatesModel should only have one PointOfInterestModel.
Now, I would like to query all my points of interest from my database, and get all the coordinates with them.
Here is what I think should work, but does not:
pointsOfInterestList = db.PointOfInterestModels.Include(x=>x.Coordinates).ToList();
So, what is wrong? Is it in the relationship, or is it in the LINQ query?
I have been trying to fix this for hours.