Overview
A set of classes are defined during the data modelling phase(s) of a project:publicclass Person: Table { [PrimaryKey] publicvirtualint Id {get; set;} [Column] publicstring 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); } }
NextAdvanced Features