I am having trouble at very long time. Lets imagine this example:
public class Coordinate {
public int id {get;set;}
public int x {get;set;}
public int y {get;set;}
}
public class Planet {
public int id {get;set;}
public string name {get;set;}
public Coordinate coordinate {get;set;}
}
I have created two models, and the model Planet has the model Coordinate as attribute. Now imagine somewhere in the code I create one coordinate and it is stored in database. Imagine this is the coordinate:
Coordinate c = new Coordinate();
c.x = 1;
c.y = 2;
Then I add it to my database and it is saved.
But when I create a planet and I do:
planet.coordinate = c;
And then I try to add it to database I have the following error:
An exception of type 'Microsoft.EntityFrameworkCore.DbUpdateException' occurred in Microsoft.EntityFrameworkCore.dll but was not handled in user code
Additional information: An error occurred while updating the entries. See the inner exception for details.
I know I can change the attribute public Coordinate coordinate
to public int coordinate_id
but I want to do this with the Coordinate model instead.
I am using ASP NET CORE 1.0
Cumps