Lets say I have an entity Foo, and it contains a list of another entity Bar. Should Bar have a direct reference to Foo? i.e…
public class Foo { public int Id {get; set;} public IList<Bar> Bars {get; set;} } public class Bar { public int Id {get; set;} public Foo parentFoo {get; set; //this will be set to an the Foo entity on creation }
or do I just leave out the reference to Foo in my Bar class?
I am leaning toward leaving that reference out, but was wondering what the correct approach is here?
The correct approach is to ask the question ‘Does Bar need to reference Foo for some reason?’ Don’t just place the reference there if Bar has no need to do anything with it.