Many-to-One VS One-to-Many

Dec 2, 2010 at 1:37 AM

First of all let me say i'm a newbie coming from old vb6... so please excuse me if i say something really really dumb ok?

In your sample i can see in the Author class that you have a reference to the Book class so you can have a collection of books inside the author object when you retrieve it.

But when i look into the Book class i would expect to see a reference to a Author class in order to load the proper Author object of that particular Book. Instead i just see the field AuthorID with no reference to any object.

Is this the only way? if i want the author of a particular book is it always required a later fetch like "Auth = new Author.FromID(bk.AuthorID)" or can i define the reference and have the object populated automatically like the books collection?

 

Coordinator
Dec 2, 2010 at 2:32 PM

This is a good question.  For whatever reason, it's not a scenario I had thought of during development so the answer, for now, anyway, is that if you select a child entity from the store, the only way to get that entity's parent is to go back to the database with the ID and ask for it.

I do, however, think that there should be a way to have a "Parent" field and have ORM fill it, so I've added this as a feature request (feel free to vote for it). Not the complexity outlined in the feature request, though.  It's not something that will be really easy to add - I have to consider how, exactly, it will work (though I'm already getting some ideas).