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.

FindAll

FindAll returns all data from a table based on a SimpleExpression defining the criteria for the search.

Syntax

public SimpleQuery FindAll(
		SimpleExpression criteria
	)

Parameters

criteria
Type: SimpleExpression
A (concatenated sequence of) search criteria. For example, dbo.Album.GenreId == 1.

Return Value

Type: SimpleQuery
A collection of SimpleRecord objects which can be iterated over.

Exceptions

Exception Condition
FormatException
- or -
BadExpressionException
criteriais a malformed SimpleExpression
BadExpressionException criteria has been assigned zero or more than one SimpleExpression

Remarks

The FindAll method is used instead of FindAllBy when the criteria is more complicated than simple equality tests. Criteria can be constructed just using regular C# expressions, with all operators supported and precedence-grouping honoured.

These C# expressions are represented internally as a SimpleExpression object. For more on SimpleExpressions, please read this page. Read also the Column Selection page for more on how to identify the columns in a SimpleExpression.

Examples

One criteria

The following example retrieves all the albums with GenreId equal to 1 and outputs their titles to the Console window.

var album = Database.Open().Albums.FindAll(db.Albums.GenreId == 1);
foreach (var album in albums)
{
  Console.WriteLine(album.Title);
}

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

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

Two Criteria

The following example retrieves all the albums with GenreId equal to 1 and ArtistId equal to 120 and outputs their titles to the Console window.

var album = Database.Open().Albums
   .FindAll(db.Albums.GenreId == 1 && db.Albums.ArtistId == 120);	
foreach (var album in albums)
{
  Console.WriteLine(album.Title);
}

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

SELECT 
    [dbo].[Album].[AlbumId], 
    [dbo].[Album].[GenreId], 
    [dbo].[Album].[ArtistId], 
    [dbo].[Album].[Title], 
    [dbo].[Album].[Price], 
    [dbo].[Album].[AlbumArtUrl] 
from [dbo].[Album]  
where 
    ([dbo].[Album].[GenreId] = @p1 AND [dbo].[Album].[ArtistId] = @p2)
@p1 (Int32) = 1
@p2 (Int32) = 120

One Criteria or Another

The following example retrieves all the albums with GenreId greater than 2 or ArtistId less than or equal to 200 and outputs their titles to the Console window.

var album = Database.Open().Albums
   .FindAll(db.Albums.GenreId > 2 || db.Albums.ArtistId <= 200);	
foreach (var album in albums)
{
  Console.WriteLine(album.Title);
}

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

SELECT 
    [dbo].[Album].[AlbumId], 
    [dbo].[Album].[GenreId], 
    [dbo].[Album].[ArtistId], 
    [dbo].[Album].[Title], 
    [dbo].[Album].[Price], 
    [dbo].[Album].[AlbumArtUrl] 
from [dbo].[Album]  
where 
    ([dbo].[Album].[GenreId] > @p1 OR [dbo].[Album].[ArtistId] <= @p2)
@p1 (Int32) = 2
@p2 (Int32) = 200