Query Interface
Represents a query.
public interface Query
Methods
Select |
Selects all columns of the specified table. |
Select<T>(string[]) |
Gets the Select<T>(string[]) object to select the specified columns of the specified table. |
Update<T>(string) |
Gets the Update object to update the specified table. |
Delete |
Gets the DeleteFrom<T>() object to delete the specified rows of the specified table. |
New |
Creates new tables. |
New |
Creates new tables. |
Insert<T>(T) |
Inserts a new row into the table. |
Insert |
Inserts a new row into the table and gets its ID. |
Select |
Gets the single row of the table in which the specified unique field matches the specified value. |
Select |
Gets all the rows of the specified table. |
Column |
Gets the column name associated with the specified parameter. |
Methods Detail
SelectAllFrom<T>(string)
Selects all columns of the specified table.
SelectFrom<T> SelectAllFrom<T>(string alias)
Type Parameters
- T
-
notnull
The type qualified with TableAttribute.
Parameters
- alias
- string
The alias of the table name.
Returns
The SelectFrom<T> object.
Select<T>(string[])
Gets the Select<T>(string[]) object to select the specified columns of the specified table.
Select<T> Select<T>(params string[] columns)
Type Parameters
- T
-
notnull
The type representing the result of this query, which must have the
single constructor accepting the parameters corresponding to columns
.
Parameters
- columns
- string[]
One or more column names. Each consists of the alias followed by a
period (.
) and the column name.
Returns
The Select<T>(string[]) object.
Update<T>(string)
Gets the Update object to update the specified table.
Update Update<T>(string alias)
Type Parameters
- T
-
notnull
The type qualified with TableAttribute.
Parameters
- alias
- string
The alias of the table name, which can be used in the Where
clause (see UpdateSet.Where(string)).
Returns
Examples
var kit = new TransactionKit(
"update_example.db", m => Console.WriteLine(m()));
var map = new Dictionary<string, object>()
{
["$id"] = 2L,
["$newState"] = "Closed",
};
kit.Execute(q =>
{
q.Update<Issue>("i")
.Set("state = $newState")
.Where("i.id = $id")
.Execute(map);
});
DeleteFrom<T>()
Gets the DeleteFrom<T>() object to delete the specified rows of the specified table.
DeleteFrom<T> DeleteFrom<T>()
Type Parameters
- T
-
notnull
The type qualified with TableAttribute.
Returns
The DeleteFrom<T>() object.
NewTables(Type[])
Creates new tables.
void NewTables(params Type[] tables)
Parameters
- tables
- Type[]
The types qualified with TableAttribute representing the tables to create.
Remarks
This method drops the tables if they exist and then creates them newly.
NewTables(IEnumerable<Type>)
Creates new tables.
void NewTables(IEnumerable<Type> allTables)
Parameters
- allTables
- IEnumerable<Type>
The types qualified with TableAttribute representing the tables to create.
Remarks
This method drops the tables if they exist and then creates them newly.
Insert<T>(T)
Inserts a new row into the table.
void Insert<T>(T row)
Type Parameters
- T
-
notnull
The type qualified with TableAttribute representing the table.
Parameters
- row
- T
The row of the table to add.
InsertAndGetRowId<T>(T)
Inserts a new row into the table and gets its ID.
long InsertAndGetRowId<T>(T row)
Type Parameters
- T
-
notnull
The type qualified with TableAttribute representing the table. It must have the field qualified with AutoIncrementAttribute.
Parameters
- row
- T
The row of the table to add.
Returns
The ID of the row newly inserted.
SelectUnique<T>(string, object)
Gets the single row of the table in which the specified unique field matches the specified value.
T SelectUnique<T>(string columnName, object value)
Type Parameters
- T
-
class
The type qualified with TableAttribute representing the table. It must have the field qualified with UniqueAttribute.
Parameters
- columnName
- string
The name of the unique field.
- value
- object
The value that the unique field matches.
Returns
The row in which the field specified with columnName
matches the specified value
if it exists,
null
otherwise.
SelectAll<T>()
Gets all the rows of the specified table.
IEnumerable<T> SelectAll<T>()
Type Parameters
- T
-
notnull
The type represents the row of the table.
Returns
All the rows of the specified table.
Remarks
The IEnumerable<T> object returned by this method is valid as long as the transaction is in progress. If you need access to it after the transaction, you must use something like the Enumerable.ToList<TSource>(IEnumerable<TSource>) method to get the list in the meantime and then use it afterward.
ColumnName<T>(string)
Gets the column name associated with the specified parameter.
string ColumnName<T>(string parameterName)
Type Parameters
- T
-
notnull
The type represents the row of the table.
Parameters
- parameterName
- string
The parameter name that the constructor of T
contains.
Returns
The column name.