Create Datatypes
Creating Data Types Programmatically
You create a data type programmatically by creating a corresponding interface inherited from IData
. You should specify a number of type attributes for the interface as well as add a number of properties with a number of property attributes.
Sample:
using System; using Composite.Data; namespace Demo { [AutoUpdateble] [KeyPropertyName("Id")] [ImmutableTypeId("{6EF1F9CC-D14B-4c63-AF4C-662089BFEDEA}")] [DataScope(DataScopeIdentifier.PublicName)] public interface IMyUser : IData { [ImmutableFieldId("{62A03F88-4A29-4182-9BCF-84080F1A2111}")] [StoreFieldType(PhysicalStoreFieldType.Guid)] Guid Id { get; set; } [ImmutableFieldId("{6AEEA24A-77AB-486c-AE6F-69EB224735A4}")] [StoreFieldType(PhysicalStoreFieldType.String, 64)] string Name { get; set; } [ImmutableFieldId("{6A085CAD-E74E-4e4b-8352-B31D9932EDCC}")] [StoreFieldType(PhysicalStoreFieldType.String, 64)] string Email { get; set; } } }
In the sample:
- The
ImmutableTypeId
attribute specifies a unique ID for the type. - The
KeyPropertyName
attribute specifies the name of the key property used as a key for the data type. - The
DataScope
attribute specifies data scopes items of the data types should exist in (DataScopeIdentifier.Public
andDataScopeIdentifier.Administrated
). - The
AutoUpdate
attribute has C1 CMS automatically add and update your type. - The
ImmutableFieldId
attribute specifies a unique ID for the property. - The
StoreFieldType
specifies the underlying type of the property.
Please also see: