Basic Code Samples

Below are some basic code samples. You can see that retrieving information from the database is easy and in most cases can be done with 1-line of code. Notice that there is a LINQ expression syntax that allows you to perform complex querying with very little syntax. Also you can query across tables with no joining. The model defines the relationships. In code you just use them. There is no explicit joining in code. This removes a problem area for developers.

Aggregates
Persisting

//Select All
CustomerCollection customerCollection = CustomerCollection.RunSelect();
System.Diagnostics.Debug.WriteLine(customerCollection.Count.ToString());

//Select By Marked Field
CustomerCollection customerCollection = CustomerCollection.SelectByCity("Berlin");
System.Diagnostics.Debug.WriteLine(customerCollection.Count.ToString());

//Using a free form LINQ expression
CustomerCollection customerCollection = CustomerCollection.RunSelect(x => x.City == "Berlin");
System.Diagnostics.Debug.WriteLine(customerCollection.Count.ToString());

//Select records from the Customer table with LINQ based on child table
//Notice there is no join syntax from Customer->Order->OrderDetail, it is implied
CustomerCollection customerCollection = CustomerCollection.RunSelect(
	x => x.Order.OrderDetail.UnitPrice < 10);
System.Diagnostics.Debug.WriteLine(customerCollection.Count.ToString());

//Select page 2, with records per page 10, sorted by ContactName ascending
//querying all customers for the city of 'Berlin'
CustomerPaging paging = new CustomerPaging(2, 10, Customer.FieldNameConstants.ContactName, true);
CustomerCollection customerCollection = CustomerCollection.RunSelect(x => x.City == "Berlin", paging);

//Select single record by primary key
Customer customer = Customer.SelectUsingPK("ALFKI");

//Client-side sorting
//Loop through customers sorted in memory by 'ContactName'
foreach (Customer customer in (from x in customerCollection orderby x.ContactName select x))
{
}

Last edited Sep 13, 2009 at 7:39 PM by codetools, version 11

Comments

No comments yet.