Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
The Dynamic Data Store (DDS) is a component offering an API and infrastructure for the saving, loading and searching of both compile time data types (.NET object instances) and runtime data types (property bags). The component is shipped as part of the Episerver Framework package.
Alternative technologies include Microsoft’s Entity Framework and NHibernate for .NET. However, the Dynamic Data Store has been specifically designed with Episerver CMS and its flexible user-driven data in mind.
The EPiServer.Data assembly contains the following main namespaces:
Use the DynamicDataStoreFactory class to create, obtain and delete stores. The class has a single instance which is obtained from the static Instance property. Alternatively, stores can be automatically created for .NET classes by decorating them with the EPiServerDataStoreAttribute and setting the AutomaticallyCreateStore property to true.
See the UsingStores class in the DDS sample project for examples on creating, obtaining and deleting stores.
Data can be saved and loaded using compile time data types (.NET classes) and runtime data types via the EPiServer.Data.Dynamic.PropertyBag class. The Dynamic Data Store is divided into logical stores which are identified by name. Stores are not polymorphic which means only one property set may be saved in a store although it is possible to re-map stores and achieve a level of polymorphism though the use of interfaces and template types.
See the LoadSaveType and LoadSavePropertyBag classes in the the DDS sample project for examples of loading and saving data.
You can search data in the Dynamic Data Store in the following ways:
See the UsingLinq and UsingFind classes in the DDS sample project for examples of searching for data.
The Dynamic Data Store is essentially an Object-Relational mapper. When used with compile time data types (.NET classes), all properties that have a public getter and a setter (setter does not need to be public) are mapped to a column in a database table. For runtime data types, each property added to a PropertyBag is also mapped in the same way.
In Dynamic Data Store all data types are stored in one database table. This table contains many columns, several of each data type that the Dynamic Data Store supports.
When a data structure is saved, the .NET CLR type of each property is mapped against an internal list of supported types. The following types of mapping supported:
Inline mapping is where a property of a class or PropertyBag can be mapped directly against one of the supported database columns. The following types can be mapped inline:
A property is mapped as a collection if it implements the System.IEnumerable interface. In this case, all elements of the collection (both keys and values in the case of System.IDictionary) are stored in a special reference table.
Even though the EPiServer.Data.Dynamic.PropertyBag implements System.IEnumerable, it will actually be treated as a reference type (see below).
All properties that cannot be mapped inline or as a collection (plus the EPiServer.Data.Dynamic.PropertyBag type) are mapped as references. This means that their properties are mapped in turn as a sub-type, and a link row is added in the reference table to link the parent data structure with the child data structure. This allows for complex trees of data structures (object graphs) to be saved in the Dynamic Data Store.
The default Dynamic Data Store table is called tblBigTable, which contains the following fixed columns (meaning mandatory columns):
The default big table also contains the following optional columns:
The columns whose name starts with Indexed have database indexes created on them.
You may want to add and remove columns in this table to suit the type of data you are saving. This is particularly useful if you are going to store a data type with more than, for example, 10 strings. By default, the 11th to 20th strings would be stored in a 2nd row for the type, which means a join has to be done at runtime when reading the data. By adding String11, String12 and so on to the big table, you limit the chance of a row overspill and therefore increase performance. If you require more indexes, then add columns with names starting with Indexed and make sure an index is created on them.
You can also add your own table. This is particularly useful if you are going to store a type that only contains strings for example. Along with the mandatory columns (pkId, Row, StoreName, ItemType), you can add about 20 StringXX columns.
Add the EPiServerDataTableAttribute with the TableName property given as the name of the custom table, to use the custom big table.
This table lists the database columns types in the default big table and the .NET CLR “inline” types they are mapped to:
Database Column Type | .NET CLR “Inline” Types |
---|---|
varbinary(max) varbinary(900) |
System.Byte[] |
int | System.Byte, System.Int16, System.Int32, System.Enum |
bigint | System.Int64 |
float | System.Single, System.Double |
datetime | System.DateTime |
uniqueidentifier | System.Guid |
nvarchar(max) nvarchar(450) |
System.String, System.Char, System.Char[], EpiServer.Data.Identity |
bit | System.Boolean |
Each store is actually represented in the database by a view. The views can be used as normal including cross joining with other tables and views in the database.
Last updated: Sep 21, 2015