This project is read-only.

Database Tables

Topics: Developer Forum
Mar 10, 2009 at 1:12 AM

I have never used N2Cms before, but am trying it out for a new project.

Probably a silly question, but I thought it would be best to ask anyway.....

From what I gather, the database uses 4 main tables for all of the items, content, etc.

My project requires additional tables for things such as membership, videos, galleries, etc.

Should I just add the additional tables into the database, or is there a better way of doing it with the framework?

Like I said, I have never used N2Cms, but am really keen to get into it. I am just unsure on how the database works.

I have read and it did give me some info, but I'm not sure how to tackle additional tables, stored procedures, etc.

Any help or advice would be much appreciated!

Thanks in advance :)
Mar 10, 2009 at 10:44 AM
You can have an infinite freedom as to what db for what tables to use.. If i were you, i'd keep n2's tables in a separate db. Moreover, because n2 is using a magical NHibernate, you can switch db provider in any moment, say, from mssql to sqlite and back. I prefer SQLite for a local development. Here's some quick facts:
  • You can generate a complete N2 schema from a scratch (after first providing a correct connection string in web.config, of course!) by navigating to ~/Edit/Install, on the 3rd step by clicking [Create Tables] you're starting everything anew
  • You can easily import/export *all* data from you db (regardless of a db server you use, be it SQLite or MS SQL) in any moment in XML format -- just use the appropriate command from a top toolbar in the edit interface
Two functions above provide you with an enormous flexibility as to what to keep where and how, what you think?
Mar 10, 2009 at 11:35 PM
Hi esteewhy,

That's awesome! Thanks for the info :)

Just one last question.... what about data integrity? Are you able to add relationships, etc, so that if a record from a parent table is deleted so are it's children, etc?

Mar 11, 2009 at 4:15 PM
Edited Mar 11, 2009 at 9:11 PM
Perhaps "table" is not the best term to describe N2's data shape (because it is inherently hierarchical by it's nature), but yes, if you delete someone somewhere in the hierarchy, then aLL children are deleted as well. The opposite stands also true: you can only insert child if you specify a parent for it. So, we can say that the basic tree-like integrity is always obeyed. But, hey, it was only a "data" (or "physical") layer part of the story! You can also establish some kind of relationship among items on a logical layer by decorating your classes with [AllowChildren] and [RestrictParents] attributes. This sort of integrity works only for the Edit GUI, so it won't help if you'll try to break it in code.