Speedy.Data allows you to create an object that automatically handles its own data interaction for Create (Insert), Read (Select), Update, and Delete statements (Automatic CRUD). This is accomplished by using attributes placed on the business object that provide metadata to Speedy.Data, which allows it to perform all of the automatic CRUD. These attriubutes provide all the information needed to perform the Object Relational Mapping (ORM) for your objects. The attributes you'll need to use are:
[SpeedyTable] - Class attribute
Place this attribute above your business object's class name to indicate it will use Auto CRUD. This attribute should be instantiated with the corresponding database table's name.
[SpeedyPrimaryKey] - Field attribute
Place this attribute above each Primary Key field on your object. It is used on all fields that are primary keys in the database. Note that you can have as many SpeedyPrimaryKey fields as you want (joint primary keys). This attribute can be instantiated with the following parameters:
- FieldName: The name of the field in the database.
- DBType: The SQL DB Type of the field.
- Identity: Is this field an identity field in the DB?
[SpeedyField] - Field attribute
Place this attribute above each field in your class for all of the non-primary key fields. This attribute can be instantiated with the following parameters:
- FieldName: The name of the field in the database.
- DBType: The SQL DB Type of the field.
- ExcludeIfZero: Set to true if you want a field to not be included in inserts and updates if its value = 0.
- IncludeInSelect: Should this field be included in Select statements? Useful if you want to exlude large amounts of data from automatic selects for performance reasons.
- IncludeInInsert: Should this field be included in Insert statements?
- IncludeInUpdate: Should this field be included in Update statements?
- Size: The length of the field in the database.
Inherit from Speedy.Data.Business.SpeedyObject
To provide you with the highest productivity boost, write your objects to inherit from Speedy.Data.Business.SpeedyObject. This will give you .Insert(), .Fill(), .Update(), and .Delete() methods for free!
Quick example
Take a look at the Hospital object below for a sample of a full class that works with Speedy.Data.
using System;
using System.Text;
using System.Data;
using Speedy.Data.SQLBuilders;
using Speedy.Data.Business;
using Speedy.Data;
//This is a simple object, and only needs to do Creates, Reads, Updates, and Deletes.
//Therefore, it does not require a Data Service Object (DSO)
namespace SampleBusinessLayer.BusinessObjects
{
//This attribute identifies the name of the Database Table associated with this object.
[SpeedyTable("TBL_HOSPITAL")]
//We'll inherit from Speedy.Data's SpeedyObject class.
public class Hospital : SpeedyObject
{
[SpeedyPrimaryKey("HospitalID", SqlDbType.Int, true)]
private int mem_HospitalID;
[SpeedyField("Name", SqlDbType.NVarChar, 50)]
private string mem_Name;
#region Properties
public int HospitalID
{
get { return mem_HospitalID; }
set { mem_HospitalID = value; }
}
public string Name
{
get { return mem_Name; }
set { mem_Name = value; }
}
#endregion
#region Constructors
public Hospital()
: base()
{
Construct();
}
public Hospital(int hospitalID)
: base()
{
Construct();
HospitalID = hospitalID;
Fill();
}
private void Construct()
{
mem_HospitalID = 0;
mem_Name = string.Empty;
}
#endregion
}
}