Creating objects

Almost all objects can be defined using the Dynamix Developer Tools plugin for Visual Studio.

First add a new item using Visual Studio's "New item..."

Select C# or VB and then "Dynamix 6 - Object". Choose a name and click Add. 

Several files are created in the solution:

The object editor is opened by double clicking the .dx6-file:

Object Properties

The main view lets you edit the object's properties. You can add as many properties as you like - just place the cursor in the Name-column of a new row and start typing its name.

Object properties can be of several types:

  • An object property models a connection to another object. This can be a locally owned (cascaded) object - e.g. an image or a link, or a global object - e.g. a page, a user or any other object that is not owned by the object being edited.

  • An object list property models a list of objects related to this object. These can also be local or global objects.

  • A text property models a string - e.g. a headline, text or name

  • Integer and decimal properties for numbers.

  • Date and time

  • Password

  • Size

  • Color

For some types (integers, dates, etc.) there are also property types for ranges and nullable versions.

Generated files and classes

The tool generates the .dx6.designer.cs or .vb-file with properties and methods that can be generated from the visual settings. In our example it will generate, among other things, properties for Page and Headline.

We can now create objects of the NewsItem-class from our code:

var item = new NewsItem { Headline = "My headline" };

Storing and editing objects

When objects are created using new, they exist only in program memory. When they go out of scope they are no longer available. To store them permanently in the database we can use the method Save from Dynamix.Storage.

Dynamix.Storage.Save( item );

As soon as the object is saved to the database, it is also written to the object cache and made available to other threads. We can no longer edit it:

var item = new NewsItem { Headline = "My headline" };
Dynamix.Storage.Save( item );

item.Headline = "New headline";

This code will throw an exception on the last statement: System.InvalidOperationException: Object NewsItem [ID:213] is not writable. It is "ReadOnly".

To write to a saved object we must first get hold of an editable copy of it:

item = Dynamix.Storage.GetEditable( item );
item.Headline = "New headline";
Dynamix.Storage.Save( item );

See also

Last updated 2016-01-14