Not sure if you can name the word for this, so feel free to edit if it is inaccurate.
Using an example, what I'm trying to do is update the record in the foo table and then create new records in the next table with the Foo PK tables as a foreign key, think of a one-to-many relationship.
How to update a table with foreign key constraints and create a new related record (s) in these subsequent tables?
I am currently using Entity Framework 6 to add .Add and .Attach to the context and store them in the database.
Edit
To clarify what I'm trying to achieve, the following object is a shortened example that I am trying to keep in context. If I try. Add intObj after “Billy Bob” has already been created, because he bought a new car, another service or his tires changed it, will create a new Billy Bob record (duplicate) and the corresponding related tables.
intObj.FirstName = "Billy";
intObj.Lastname = "Bob";
intObj.Important = 100;
intObj.LastSeen = DateTime.Now.Date;
intObj.Cars = new List<Car>{
new Car{
Model = "Commodore",
Make = "Holden",
YearMade = DateTime.Today.Date,
Odometer = 15000,
EmailWordCount = 500,
TyreStatuss = new List<TyreStatus>{
new TyreStatus{
Tyre1 = "Good",
Tyre2 = "Good",
Tyre3 = "Okay",
Tyre4 = "Okay"
}
},
Services = new List<Service>{
new Service{
Cost = "$500",
Time = "2 Days",
Date = DateTime.Today
}
},
}
};
thank
source
share