Use Case: Deriving creation scripts from design

Abstract

You don't always want DataClass to tell you what to do, obviously, so we give you the ability to put any SQL transition scripts in you like. Then we augment that with the ability to bind in symbols from your delineation of design. A lot of the time, however, you don't really want to do anything special - you just want a standard way of declaring a table or column. For that reason, we've added a few simple "shortcut" attributes to certain special design elements.

Learning Objectives

  • How to shorten your time to development
  • How using derived properties eliminates duplication

Body

Table, column, and parameter design elements all get the Declaration property filled in by DataClass automatically. The Declaration property takes into account the name of the design element as well as all aspects of its DataType property, if there is one.

You can click on keywords and concepts in blue.
// Declaration = A(something NVARCHAR(10), Y INT, Z NUMERIC(12, 4))
handpublic table A ("tblA")
{
  // Declaration = something NVARCHAR(10) NOT NULL
  public column X ("something") with DataType = type(nvarchar(10) null);
  // Declaration = Y INT NOT NULL
  public column Y with DataType = type(int);
  // Declaration = Z NUMERIC(12, 4) NULL
  public column Z with DataType = type(numeric(12, 4) null);
}
// Declaration = L NVARCHAR(10) = NULL
parameter L : A.X;
// Declaration = M INT
parameter M : A.Y;
// Declaration = N NUMERIC(13, 5)
parameter N with DataType = type(numeric(13, 5));

Column and parameter design elements also have the following properties filled in automatically whenever the required data are present:

  • CoreType
  • BaseDataType
  • Length
  • Precision
  • Scale

The CoreType property represents the basic type of the parameter or column, taking into account length, precision, and scale but not nullness. This property is useful for declaring local variables with the same type as a column or a parameter.

You can click on keywords and concepts in blue.
// CoreType = NVARCHAR(10)
handpublic column X with DataType = type(nvarchar(10) null);
// CoreType = INT
public column Y with DataType = type(int);
// CoreType = NUMERIC(12, 4)
public column Z with DataType = type(numeric(12, 4) null);

The BaseDataType property represents the kind of data associated with a design element it does not take into account length, precision, scale or nullness. It use useful for defining artifacts with the same basic kind of data as whatever you have specified in a design element but with different properties.

You can click on keywords and concepts in blue.
// BaseDataType = NVARCHAR
handpublic column X with DataType = type(nvarchar(10) null);
// BaseDataType = INT
public column Y with DataType = type(int);
// BaseDataType = NUMERIC
public column Z with DataType = type(numeric(12, 4) null);

Length is the length the data type associated with a design artifact. String and binary types tend to have lengths.

You can click on keywords and concepts in blue.
// Length = 10
handpublic column X with DataType = type(nvarchar(10) null);
// No length
public column Y with DataType = type(int);
// No length
public column Z with DataType = type(numeric(12, 4) null);

The precision property corresponds with the precision part of a type's declaration (the first of two numbers).

You can click on keywords and concepts in blue.
// No precision
handpublic column X with DataType = type(nvarchar(10) null);
// No precision
public column Y with DataType = type(int);
// Precision = 12
public column Z with DataType = type(numeric(12, 4) null);

The scale property corresponds with the scale part of a type's declaration (the second of two numbers).

You can click on keywords and concepts in blue.
// No scale
handpublic column X with DataType = type(nvarchar(10) null);
// No scale
public column Y with DataType = type(int);
// Scale = 4
public column Z with DataType = type(numeric(12, 4) null);

All of these properties can be bound directly into your construction logic just like any property of any design element. They are also available to clients.

Related Use Cases

Related Keywords

Other Actions

documentation | all examples | use cases | concepts | keywords