I have a robust set of objects that relate to one another and I need to figure out that best way to handle saving them to the database and still account for things like data constraints.
Let's say I have the following classes:
class Foo
{
public int Id { get; set; }
public int BarId { get; set; }
Bar _bar;
public Bar Bar
{
get { return _bar; }
set
{
if(_bar != value)
{
_bar = value;
BarId = value.Id;
}
}
}
}
class Bar
{
public int Id { get; set; }
}
Then let's say I have the following code:
var f = new Foo() { Bar = new Bar() };
SaveFoo(f);
What should I do in SaveFoo to save the objects to the database in the proper order?
IMPORTANT NOTE: I am code generating all of this from my SQL data structure using MyGeneration, and I have access to all Constraints while I'm generating.