Beispiel #1
0
        static public EntityFieldDef AddEntityFieldDef(Guid entityDefId, string fieldName, string caption, DataTypes dataType, int length)
        {
            FieldMetadata metadata = MetadataManager.NewDataNode((int)DataNodeTypes.Field) as FieldMetadata;

            metadata.Initialize(
                Guid.NewGuid(),
                fieldName,
                (int)DataNodeTypes.Field,
                entityDefId);

            metadata.Caption  = caption;
            metadata.Nullable = true;
            if (dataType == DataTypes.String)
            {
                if (length < 0)
                {
                    metadata.Length = 0;
                }
                if (length > 256)
                {
                    metadata.Length = 256;
                }
            }
            else
            {
                metadata.Length = 0;
            }
            try
            {
                MetadataManager.CreateDataNode(metadata);
            }
            catch (Exception ex)
            {
                throw new MetadataException(ex.Message, ex);
            }
            return(FieldMetadataToFieldDef(metadata));
        }