Interface IProjectionQuery<T>
Represent result of projection operation.
Inherited Members
Namespace: Kros.KORM.Query
Assembly: Kros.KORM.dll
Syntax
public interface IProjectionQuery<T> : IQueryBase<T>, IOrderedQueryable<T>, IQueryable<T>, IEnumerable<T>, IOrderedQueryable, IQueryable, IEnumerable
Type Parameters
Name | Description |
---|---|
T | Type of model class. |
Methods
Any(RawSqlString, Object[])
Check if exist elements in the table which match condition.
Declaration
bool Any(RawSqlString whereCondition, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
RawSqlString | whereCondition | The where condition. |
System.Object[] | args | The arguments for where. |
Returns
Type | Description |
---|---|
System.Boolean | true if exist elements in the table which match condition; otherwise, false. |
Examples
var exist = database.Query<Person>().Any("Age > @1", 18);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if |
Any(FormattableString)
Check if exist elements in the table which match condition.
Declaration
bool Any(FormattableString whereCondition)
Parameters
Type | Name | Description |
---|---|---|
System.FormattableString | whereCondition | The where condition. |
Returns
Type | Description |
---|---|
System.Boolean | true if exist elements in the table which match condition; otherwise, false. |
Examples
var exist = database.Query<Person>().Any($"Age > {18}");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if |
FirstOrDefault(RawSqlString, Object[])
Returns the first item of which match where condition, or a default value if item doesn't exist.
Declaration
T FirstOrDefault(RawSqlString whereCondition, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
RawSqlString | whereCondition | The where condition. |
System.Object[] | args | The arguments for where. |
Returns
Type | Description |
---|---|
T | null if item doesn't exist; otherwise, the first item which match the condition. |
Examples
var item = query.FirstOrDefault("Id = @1", 22);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if |
FirstOrDefault(FormattableString)
Returns the first item of which match where condition, or a default value if item doesn't exist.
Declaration
T FirstOrDefault(FormattableString whereCondition)
Parameters
Type | Name | Description |
---|---|---|
System.FormattableString | whereCondition | The where condition. |
Returns
Type | Description |
---|---|
T | null if item doesn't exist; otherwise, the first item which match the condition. |
Examples
var item = query.FirstOrDefault($"Id = {22}");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if |
GroupBy(String)
Add group by statement to sql query.
Declaration
IGroupedQuery<T> GroupBy(string groupBy)
Parameters
Type | Name | Description |
---|---|---|
System.String | groupBy | The group by statement. |
Returns
Type | Description |
---|---|
IGroupedQuery<T> | Query for enumerable models. |
Remarks
You can also add HAVING statement.
Examples
var people = database.Query<Person>().GroupBy("FirstName, LastName");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if |
OrderBy(String)
Add order by statement to sql.
Declaration
IOrderedQuery<T> OrderBy(string orderBy)
Parameters
Type | Name | Description |
---|---|---|
System.String | orderBy | The order by statement. |
Returns
Type | Description |
---|---|
IOrderedQuery<T> | Query for enumerable models. |
Examples
var people = database.Query<Person>().OrderBy("FirstName DESC, LastName");
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if |
Where(RawSqlString, Object[])
Add where condition to sql.
Declaration
IFilteredQuery<T> Where(RawSqlString whereCondition, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
RawSqlString | whereCondition | The where condition. |
System.Object[] | args | The arguments for where. |
Returns
Type | Description |
---|---|
IFilteredQuery<T> | Query for enumerable models. |
Examples
var people = database.Query<Person>().Where("Id < @1 AND Age > @2", 1000, 18);
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if |
Where(FormattableString)
Add where condition to sql.
Declaration
IFilteredQuery<T> Where(FormattableString whereCondition)
Parameters
Type | Name | Description |
---|---|---|
System.FormattableString | whereCondition | The where condition. |
Returns
Type | Description |
---|---|
IFilteredQuery<T> | Query for enumerable models. |
Examples
var item = query.Where($"Id = {1}")
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | if |