SubSonic SimpleRepository doesn't seem to have a lot of support for foreign relations. How can I have foreign relationships in my code models that persist and load from the database naturally?
+1
A:
FKs are a DB concern - the Simple Repo is there to work as simply as possible so if you have a collection of child objects, you load them as needed:
public IEnumerable Kids{
get{
return Kids.All().Where(x=>x.ParentID==this.ID;
}
}
You'd have to roll this by hand. If you want to "eager" load it - do on a case by case basis.
Rob Conery
2009-12-30 21:01:00
Hey Rob, thanks for responding. I was hoping for something that didn't involve a round-trip to the DB with every access on the property.What about for one-to-one relations? Say, for just one kid.
Anton
2009-12-31 19:24:12
Just code it that way - you can have a local variable and return it if it's not null - if it is hit the DB :). The nice part is that you solve issues in the code, not by banging on the ORM (thus the name) - it's pretty bare metal :)
Rob Conery
2009-12-31 21:28:49