This project is read-only.

Overview

A set of classes are defined during the data modelling phase(s) of a project:

public class Person: Table
{
   [PrimaryKey]
   public virtual int Id {get; set;}

   [Column]
   public string Names {get; set;}

   [Column]
   public Nullable<DateTime> DateOfBirth {get; set;}
}

Additions and changes to the data model are deployed to the underlying database

var context = new SqlContext("ConnectionName");
var deployment = new SqlDeployment(context);
                
deployment.DeploymentMode = DeploymentMode.Update; //Preserve existing data
deployment.DeploymentType = DeploymentType.Deploy;

deployment.Deploy(typeof(Person).Assembly);

Person instances are manipulated using methods inherited from the underlying Table class (classes can implement an interface if preferred) and a Command object:

var command = context.CreateCommand();

var person = new Person();
person.Id = 1;
person.Names = 'James Doe';
person.Insert(command);

var person2 = new Person();
person2.Id = 1;
person2.Select(command);
person2.DateOfBirth = '23 April 1974';
person2.Update(command);

The Query<T> class can be used to return multiple instances of objects, with grouping filtering and sorting, as well as supporting joins to other queries.

var personQuery = new Query<Person>();
personQuery.OrderBy.Add(personQuery.GetColumn("DateOfBirth");

using (QueryDataAdapter adapter = personQuery.Execute(command))
{
   while (adapter.Read())
   {
      CalculateAge(personQuery.Item.DateOfBirth);
   }
}

Next Advanced Features

Last edited Jan 28, 2010 at 10:45 PM by JamesWestgate, version 23

Comments

No comments yet.