Simple.Data

Simple.Data defines a number of commands for retrieving data from a data store. These can then be daisychained in a LINQ-like fashion with further methods to modify the basic query.

Get

The Get method returns a single row of data as a SimpleRecord object given values for the primary key columns of that table.

Syntax

public SimpleRecord Get(
		object[] primaryKeyValues
	)

Parameters

primaryKeyValues
Type: object[]
Values for each of the primary key columns in the target table.

Return Value

Type: SimpleRecord
An object containing a property for each of the columns requested by Simple.Data whose values are those of the single row retrieved from the data store.

Exceptions

Exception Condition
ArgumentException You have specified zero or an incorrect number of named parameters for primaryKeyValues
FormatException One of the values in primaryKeyValues is of the wrong type

Remarks

If Get is sent primaryKeyValues that do not correspond to a row in the data source, it will return null.

[ADO Adapter Only]

Get will use the table’s primary key to construct the query (once; it’s then cached internally, no worries about performance).

If a table has a compound primary key, Simple.Data arbitrarily assigns individual primaryKeyValues to the key columns in the order the latter were defined.

[MongoDB Adapter Only]

Get will compare primaryKeyValues against the built-in id value that Mongo assigns to all records.

[OData Adapter Only]

Customers.Get(1001) will resolve to the /Customers(1001) URL.

Examples

The following example retrieves the album with AlbumId equal to 386 and outputs its title to the Console window. AlbumId is the primary key of the Album table.

var album = Database.Open().Albums.Get(386);
Console.WriteLine(album.Title);

Simple.Data sends the following SQL to the database when album is evaluated.

select TOP 1   
   [dbo].[Album].[AlbumId],
   [dbo].[Album].[GenreId],
   [dbo].[Album].[ArtistId],
   [dbo].[Album].[Title],
   [dbo].[Album].[Price],
   [dbo].[Album].[AlbumArtUrl] 
from [dbo].[Album]
where 
   [AlbumId] = @p1
@p1 (Int32) = 386