Dynamic Types

This topics describes the concepts of working with Dynamic Types

Creating a new dynamic type

As mentioned in the Dynamic Data overview section, Sitefinity Fluent API allows you to work with dynamic types of data. Every dynamic type is stored in separate table in the Sitefinity database. Let's see how a dynamic data type can be created:

using Telerik.Sitefinity;
using Telerik.Sitefinity.Metadata.Model;
...
protected void addDynamicType_Click(object sender, EventArgs e)
{
    App.WorkWith()
       .DynamicData()
       .Type()
       .CreateNew("ContactInfo", "Telerik.Sitefinity.DynamicTypes.Model")
       .Do(dt => dt.DatabaseInheritance = DatabaseInheritanceType.vertical)
       .Field()
            .CreateNew("FirstName", typeof(string))
            .Done()
       .Field()
            .CreateNew("LastName", typeof(string))
            .Done()
       .Field()
            .CreateNew("Age", typeof(int))
            .Done()
       .SaveChanges(true);
}

Intead of working with fields this time (showed in Dynamic Fields), we are creating a new type by calling CreateNew() directly. The first perimeter here specifies the new data type class name, while the second - the namespace. Specifying DatabaseInheritanceType actually tells Sitefinity how to persists the fields in the database tables.

What is following is using the Child Facade Field() several times, for creating each of the dynamic fields of this content type. As shown in the Child Facades topic, by calling the Done() method we are again allowed to use the parant facade.

Funally after all the fields are created, we call SaveChanges(). The true boolean parameter which is used in SaveChanges() is used to tell Sitefinity that the database should be upgraded - in other words, there are structural changes to database which should be done.

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK