Child to father relationship design using managed backing fieldsChild to father relationship design using managed backing fields
Old forum URL: forums.lhotka.net/forums/t/7944.aspx
shrage posted on Wednesday, November 04, 2009
When you have a category / sub category relationship usually you have one table called Categories with a field called ParentCategoryId which referece to the primary key of the same categories table. for example lets i have a list of people and i want to create a relationship between father's and sons. i have a table called Persons which primary key PersonID, each person has a field called FatherId which refers to a PersonKey in the same persons table.
Unlike normal patent and child relationships, when you have categories and subcategories, each category is a root and a child, for example you have a hierarchy of father and sons, when you load a person this person has a father and and this person has a son, what if i want to make a Father property which lazy loads another person object where it's id = the son's FatherID. how can i accomplish this, rocky's example of lazy loading passed a "parent" object to a factory method like ChildGet(parent) and the child knows how to load itself by a query like this 'select child where parentid = parent.id' but in our case its the opposite we ask the child (son) to load its father saying something like this GetFather(fatherid) which should result in a sql statement like this 'select person where id = son.fatherid. how can i accomplish this lazy loading technique using managed backing fields?Copyright (c) Marimer LLC