Overview Support Download Purchase

Using TurnObjects

Once a system has been compiled by TurnObjects it's objects can be used in the application. The assembly could be added as a reference to the project but TurnObjects allows for more power and flexibility by loading the assembly at runtime. Using this method, the code will not have to change if the TurnObjects system changes.

Create an Instance of a TurnObject

Creating an instance of an object in the system is done by specifing the system and the schema that represents the object. The methods for creating an object are as follows:

Create an Instance From the System

BaseObject CreateInstance(string schemaName)

This will return the object cast as a BaseObject. It may need to be cast to a more specific TurnObjects base object.

Copy 

Loading an Object

Load By Primary Key

An object is normally loaded by it's primary key. The process of loading an object is done by specifing the key and calling the Load() method. The following example loads the ContactPerson with the id of 1.

Copy 

Load By Alternate Key

It is also possible to load the object by any other property marked as IsLoadBy. When the object is generated the methods for loading by the specified property are generated. The load by value should be unique to the object so that the correct object can be retrieved. The following shows an example of loading a contact by their social security number.

Copy 

Accessing an Objects Properties

objectInstance["propertyName"]

A loaded object's properties can be accessed by using the braces operator and specifing the required property. this method returns an object so the value may need to be cast to the disired type. For example the following will return the first name of a contact person cast as a string.

Copy 

There are also specific methods to get and set the property values. This method is slightly faster and will return the value using the intended type.

MethodDescription
string GetString(string propertyName)
SetString(string propertyName,string value)
Get and set string values.
DateTimeGetDateTime(string propertyName)
SetDateTime(string propertyName,DateTime value)
Get and set DateTime values.
int32 GetInteger(string propertyName)
SetInteger(string propertyName,Int32 value)
Get and set integer values.
Decimal GetDecimal(string propertyName)
SetDecimal(string propertyName,Decimal value)
Get and set decimal values.
float GetFloat(string propertyName)
SetFloat(string propertyName,float value)
Get and set float values.
long GetLong(string propertyName)
SetLong(string propertyName,long value)
Get and set long values.
Guid GetGuid(string propertyName)
SetGuid(string propertyName,Guid value)
Get and set guid values.
string GetOption(string propertyName) Get the string representation of a property whose foreign type is an OptionCollection.

Using the example from above the new methods would be:

Copy 

Save an Object

Saving an object is done by calling the save method. The object will use the specified method for saving the object as specified by it's SaveMethodType. The following examples loads a contact with an id of 1, changes the email address and saves it.

Copy 

TurnObjects Collection

Collections of objects inherit from the System.Collections.CollectionBase. A collection of TurnObjects is accessed by creating an empty collection from the system, specifying the filters (if any) and calling the load method.

Load Collection

This method will load all the items in the collection. The following example loads a collection of ContactPerson items in the ContactData system.

Copy 

Load Collection With Filter

This method will load all the items that conform to the specified property and filter text. The following example will load all ContactPerson items with Smith as a last name.

Copy 

Load Collection With Search

This method will look at all the search properties and load the collection based on any matches that are like the search text. The following example will search for the text Smith in the ContactPerson items

Copy 

Load Collection With Custom Query

This method will use a customized query to load the collection. Customized queries are defined on each objects schema. Any inputs to the query are done by using the SetQueryInput method. The following example will load the collection using the LastNameSearch custom query and Smith as the last name.

Copy 

Collection View

The collection view will return a DataTable with the specified properties. This is useful when a object is made up of other sub-objects and a combination of these objects into one view is required.

The collection view requires a TurnObjects collection to create the view from. The following example shows a simple view that is created from the targetCollection.

Copy 

Selecting Columns

By default the schema's properties indicate if they are included in the grid view. The SelectedColumns on the collection view is used to override the default columns. SelectedColumns holds a list of strings that specify which columns will be included in the view. If no columns are specified the view will use the default.

Summary Data

Summary data is calculated using the specified ReportOperation for each property. Summary data will be calculated if EnableSummary is set to true. Calculated values are held in the Summary array on the view.

Raw Data Mode

By default, the view that is created contains strings representing the values in view. This is so that any display formats, etc. can be honored. If this operation is not wanted, RawDataMode should be set to true. RawDataMode ensures the columns in the DataTable are of the type specified by the property.


© 2008 TurnObjects All rights reserved.  Legal  |  Privacy