Interface IQueryBase<T>
Interface, which describe class for executing query.
Instance which implement this interface can be used for creating and executing query for T model.
Namespace: Kros.KORM.Query
Assembly: Kros.KORM.dll
Syntax
public interface IQueryBase<T> : IOrderedQueryable<T>, IQueryable<T>, IEnumerable<T>, IOrderedQueryable, IQueryable, IEnumerable
Type Parameters
| Name | Description |
|---|---|
| T | Type of model class. |
Methods
AsDbSet()
Returns the collection of all entities that can be queried from the database.
Declaration
IDbSet<T> AsDbSet()
Returns
| Type | Description |
|---|---|
| IDbSet<T> |
ExecuteScalar()
Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
Declaration
object ExecuteScalar()
Returns
| Type | Description |
|---|---|
| System.Object | The first column of the first row in the result set, or null if the result set is empty. Returns a maximum of 2033 characters. |
Examples
var id = (int)database.Query<Person>()
.Select(p => new { p.Id })
.Where("FirstName = @p1 AND LastName = @p2", "Michael", "Štúr")
.ExecuteScalar();
ExecuteScalar<TRet>()
Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
Declaration
TRet? ExecuteScalar<TRet>()
where TRet : struct
Returns
| Type | Description |
|---|---|
| System.Nullable<TRet> | The first column of the first row in the result set as nullable type of TRet. If the result set is empty, then HasValue is false. Returns a maximum of 2033 characters. |
Type Parameters
| Name | Description |
|---|---|
| TRet | Return type. |
Examples
var id = (int)database.Query<Person>()
.Select(p => new { p.Id })
.Where("FirstName = @p1 AND LastName = @p2", "Michael", "Štúr")
.ExecuteScalar();
ExecuteStringScalar()
Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
Declaration
string ExecuteStringScalar()
Returns
| Type | Description |
|---|---|
| System.String | The first column of the first row in the result set as string, or null if the result set is empty. Returns a maximum of 2033 characters. |
Examples
var id = (int)database.Query<Person>()
.Select(p => new { p.Id })
.Where("FirstName = @p1 AND LastName = @p2", "Michael", "Štúr")
.ExecuteScalar();