Hi my site has the following database structure:
Sections
- Id (PK, Identity)
- Name
Documents
- Id (PK, Identity)
- SectionId (FK to Sections)
Articles
- Id (PK, FK to Documents)
- Title
- Content
Links
- Id (PK, FK to Doucments)
- Title
- SomeOtherField
MetaComponent
- Id (PK, FK to Documents)
- MetaKeywords
- MetaDescription
SectionComponents
- SectionId (FK to Sections)
- ComponentName
The site contains multiple sections (Articles and Links in the above structure). The Articles and Links tables extend the Document with the extra fields that only apply for that particular section. Each section can optionally have additional Components added to them. The MetaComponent table is an example of one particular Component which includes the search engine meta information.
I was wondering if it’s possible to map my application so i can query all Articles and join it to get the meta Information for that particular article. I know i could add a Meta property against my Article class but i want to be able to easily switch on and off which components apply to particular sections. I guess i would have to do something a little fancier to retrieve this information and would appreciate it if someone could help.
I hope i’ve explained things clear enough.
Thanks
firstly- one of the biggest advantages of nHib (or any ORM, for that matter) is that it enables you to view your app domain as entities rather than tables.
So in your case, I think it would be more correct, and more understandable, to look at your Document entity as being a base-class, of which Link and Article are sub-classes.
And when we look at it like that, the solution to your problem is obvious- mapping of subclasses:
* fluent nHib docs for mapping inheritance,
* more detailed info can be found in the nHib docs.