Data Types

This topic lists common LS One data types, how to use them and give examples of how they are used in the system.

RecordIdentifier

The RecordIdentifier class is widely used in the LS One code base and is used to represent primary keys or ID fields for business objects. You will commonly find references to RecordIdentifier objects in data provider classes on functions like these:

public virtual DataEntity Get(IConnectionManager entry, RecordIdentifier ID)
public virtual void Delete(IConnectionManager entry, RecordIdentifier ID)

The purpose of the RecordIdentifier is to store the information needed to uniquely identify a record.

Location

To use the RecordIdentifier class you need the following references:

  • LSOne.Utilities

Storing and reading data

The RecordIdentifier class can store a number of predefined .NET data types that represent commonly used SQL data types used in primary key fields.

Storing a value

A RecordIdentifier can store a number of known .NET data types:

  • int
  • Int64
  • Guid
  • string
  • decimal
  • DateTime
  • Date
  • bool
  • object

To store a value in a RecordIdentifier variable, you simply assign it directly to the variable like this:

RecordIdentifier recordIdentifier = "stringValue";

In the example above we are assigning a string value to the variable, but to use any of the data types mentioned above you simply assign the value directly to the RecordIdentifier variable.

Reading a value

To read a value back into a corresponding variable you simply cast the value stored in the RecordIdentifier variable. Using the string example above you would achieve this like this:

string stringValue = (string)recordIdentifier;

For the other data types mentioned above you simply apply the appropriate cast to the RecordIdentifier variable.

Storing multiple values in a single RecordIdentifier

In many cases you have more than one field in your database tables that represent the primary key. In those cases you can utilize the params constructor of the RecordIdentifier:

RecordIdentifier recordIdentifier = new RecordIdentifier("value1", "value2", "value3");

You can pass as many values as you need to this constructor.

Reading multiple values from a single RecordIdentifier

A RecordIdentifier can be indexed like a list or an array. In order to access each field in the RecordIdentifier variable, you can use the following method:

string value1 = (string)recordIdentifier[0];
string value2 = (string)recordIdentifier[1];
string value3 = (string)recordIdentifier[2];

You still need to apply the appropriate casting to get the string value from each field of the RecordIdentifier.

Usability and functionality

This section covers some practical functions of the RecordIdentifier class.

Determining the data type

You can ask the RecordIdentifier for its type by using the following functions:

  • IsGuid()
  • IsInteger()
  • IsBigInt()
  • IsDateTime()
  • IsDate()
  • IsDecimal()
  • IsEmpty()

IsEmpty is a special case and is only true if you have a RecordIdentifier that was instantiated but not assigned any specific value.

RecordIdentifier recordIdentifier = new RecordIdentifier();

This RecordIdentifier variable would return true from the IsEmpty() function since it has not yet been assigned a value.

Comparing RecordIdentifiers

You can use the equals operator == to compare two RecordIdentifier variables, or you can compare the value of a RecordIdentifier to a specific .NET value.

Example 1: Comparing two RecordIdentifiers

RecordIdentifier recordIdentifier1 = "Value1";
RecordIdentifier recordIdentifier2 = "Value2";
	
if(recordIdentifier1 == recordIdentifier2)
{
	// Do something
}

Example 2: Comparing a RecordIdentifier to a value

RecordIdentifier recordIdentifier = "Value1";
if((string)recordIdentifier == "stringValue")
{
	// Do something
}

You only need to cast the RecordIdentifier to an appropriate data type when comparing to a known data type like a string or an int.

DataEntity

The DataEntity class is used as a base class for all business object classes in LS One and forms the base for all data driven controls such as the DualDataCombobox.

Location

The DataEntity base class is defined in:

  • LSOne.DataLayer.BusinessObjects
  • LSOne.Utilities

Extending the DataEntity class

When you write your own business object class (chapter How to access new data) you need to have it extend the DataEntity class:

public class Criminal : DataEntity

This is required if you intend to use any of the built in controls and data access functionality which are all based on the DataEntity class.

Inherited fields

When you extend the DataEntity class there are two fields that are of note: ID and Text. You do not have to declare them in your extended class but you do need to populate them with data in the corresponding data provider.

ID

The ID field is of type RecordIdentifier and you should use this base field to store the primary key fields of your business object.

Text

The Text field is of type string intended to store the description field of your business object.

Populating ID and Text with data

If we look at the Criminal business object defined in chapter How to access new data we see that neither ID nor Text are defined in the extended class:

public enum GenderEnum
{
	Male,
	Female,
	Unknown
}
	
public class Criminal : DataEntity
{
	public Criminal() : base()
	{
		Gender = GenderEnum.Unknown;
		Age = 0;
	}
	
	public GenderEnum Gender { get; set; }
	public int Age { get; set; }
}

You will need to populate those fields with data from the database in the populator function:

private static void PopulateCriminal(IDataReader dr,
				       DataLayer.DataEntities.Criminal criminal)
{
	criminal.ID = (Guid)dr["ID"];
	criminal.Text = (string)dr["Alias"];
	criminal.Gender = (GenderEnum)dr["Gender"];
	criminal.Age = (int)dr["Age"];
}

Examples of usage

When you use a data control such as DualDataCombobox it will use the base class definition of your business object to display the ID and/or Text fields to the user. In the picture below, we can see a list of retail groups being displayed in a DualDataCombobox. The DualDataCombobox simply looks up the ID and Text fields of the base class to populate the list: