How data is stored in the Content Repository
From Sense/Net 6.0 Wiki
The Sense/Net Content Repository is a structured data storage repository that is at the very core of Sense/Net 6.0. Contents are stored one by one in this repository in a searchable and indexable way.
To understand how the Content Repository handles data you have to understand how Content Types are defined with Content Type Definitions.
When defining a Content Type with a Content Type Definition the following things are specified:
- Metadata of the content: name, parent content type, title, description, icon
- Fields of the Content Type (which are named Content Fields)
Contents |
[edit] Example Content Type Definition
As an example Content Type Definition let's define a Product Content Type inheriting from the WebContent type.
We want the Product Content Type to have the following fields:
- Title
- ShortTitle
- RelatedImage
- Price
- SpecialPrice
Note that because of inheriting from WebContent the newly created Product Content Type will also have all the fields that the WebContent Content Type does. These fields are the following:
- ValidFrom
- ReviewDate
- ArchiveDate
- ValidTill
- Index
<ContentType name="Product" parentType="WebContent" handler="SenseNet.ContentRepository.Folder" xmlns="http://schemas.sensenet.hu/SenseNet/ContentRepository/ContentTypeDefinition"> <Title>Product</Title> <Description>A product content type</Description> <Icon>Product</Icon> <Fields> <Field name="Title" type="ShortText"> <Title>Title</Title> <Description>The name of the product as it will appear</Description> <Icon>field.gif</Icon> </Field> <Field name="ShortDescription" type="ShortText"> <Title>Short Description</Title> <Icon>field.gif</Icon> </Field> <Field name="RelatedImage" type="Reference"> <Title>Main Image</Title> <Description></Description> <Icon>field.gif</Icon> <Configuration> <AllowMultiple>false</AllowMultiple> <AllowedTypes> <Type>File</Type> <Type>Image</Type> </AllowedTypes> </Configuration> </Field> <Field name="Price" type="Number"> <Title>Price</Title> <Description>Price of the product</Description> <Icon>field.gif</Icon> <Configuration> <MinValue>5</MinValue> <MaxValue>1200</MaxValue> </Configuration> </Field> <Field name="SpecialPrice" type="Number"> <Title>Special Price</Title> <Description>Special price if the product is on sale</Description> <Icon>field.gif</Icon> <Configuration> <MinValue>5</MinValue> <MaxValue>1200</MaxValue> </Configuration> </Field> </Fields> </ContentType>
[edit] Example of an exported Content
When cerating an instance of this Porduct Content Type the newly created content is stored in the Content Repository with all its fields. If you exported the content with the Export/Import tool you would get the foolowing XML:
<?xml version="1.0" encoding="utf-8"?> <ContentMetaData> <ContentType>Product</ContentType> <ContentName>HD-Camera-Recorder</ContentName> <Fields> <Title>HD Camera Recorder</Title> <ShortDescription>This camera may not have been first out of the gate with a flash-based camcorder--or second, or third--but one of its debut models gets it right the first time. A sleek, matte-gray compact model with a well-rounded feature set, great video, and excellent performance, the HD-Camera-Recorder definitely deserves a spot on your short list of potential home-movie camcorders. </ShortDescription> <RelatedImage> <Path>/Root/Products/HD-Camera-Recorder/video_1.jpg</Path> </RelatedImage> <Price>599.9900</Price> <SpecialPrice>549.9900</SpecialPrice> <ValidFrom>0001-01-01T00:00:00</ValidFrom> <ReviewDate>0001-01-01T00:00:00</ReviewDate> <ArchiveDate>0001-01-01T00:00:00</ArchiveDate> <ValidTill>0001-01-01T00:00:00</ValidTill> <Index>0</Index> </Fields> </ContentMetaData>
Note that when exporting contents version information is not exported as of now, only the latest version is retreived. Also note that when exporting security information and creation information is lost as well.
[edit] Mapping between Fields and the Database
The Sense/Net Content Repository hides the details of how it maps the fields of Content Types and database fields. It automatically takes care of these mappings and as end user or developer programming against the Content Repository API you need not be aware of this process.
Therefore only brief details are given on this mapping - for more detailed information you can simply discover the database structure yourself - due to the the large number of foreign keys and naming conventions this is not a difficult task.
Fields are mapped to three different types of tables based on their Repository Datatype. Int, Currency, DateTime and most String types are mapped to a flat table having a large number of columns. Text, Reference and Binary types are all mapped to their own, special table with one row per field. Information on which to which content these fields belong to are also stored within these tables.
Another important notice is that the Content Repository stores data not by contents but by versions. Whenever a content is created its first version is created along with it.
