Show / Hide Table of Contents

    Interface IQuery<T>

    Interface, which describe class for executing query.

    Instance which implement this interface can be used for creating and executing query for T model.

    Inherited Members
    ISelectionQuery<T>.Select(String[])
    ISelectionQuery<T>.Select(String)
    ISelectionQuery<T>.Select<TResult>(Func<T, TResult>)
    IFromQuery<T>.From(String)
    IProjectionQuery<T>.Where(RawSqlString, Object[])
    IProjectionQuery<T>.Where(FormattableString)
    IProjectionQuery<T>.FirstOrDefault(RawSqlString, Object[])
    IProjectionQuery<T>.FirstOrDefault(FormattableString)
    IProjectionQuery<T>.Any(RawSqlString, Object[])
    IProjectionQuery<T>.Any(FormattableString)
    IProjectionQuery<T>.OrderBy(String)
    IProjectionQuery<T>.GroupBy(String)
    IQueryBase<T>.AsDbSet()
    IQueryBase<T>.ExecuteScalar()
    IQueryBase<T>.ExecuteStringScalar()
    IQueryBase<T>.ExecuteScalar<TRet>()
    Namespace: Kros.KORM.Query
    Assembly: Kros.KORM.dll
    Syntax
    public interface IQuery<T> : ISelectionQuery<T>, IFromQuery<T>, IProjectionQuery<T>, IQueryBase<T>, IOrderedQueryable<T>, IQueryable<T>, IEnumerable<T>, IOrderedQueryable, IQueryable, IEnumerable
    Type Parameters
    Name Description
    T

    Type of model class.

    Remarks

    When you don't use Select or From function, than default values are taken from model.

    Examples

    You can use standard string sql query for querying data.

                    var people = database.Query<Person>().Sql(
                "SELECT p.Id, FirstName, LastName, PostCode " +
                "FROM Person " +
                "JOIN Address ON (Person.AddressId = Address.Id) " +
                "WHERE Age > @1", 18);
    
        foreach (var person in people)
        {
            Console.WriteLine(person.FirstName);
        }</code></pre>
    

    You can use sql query builder.

                    var people = database.Query<Person>()
                .Select("p.Id", "FirstName", "LastName", "PostCode")
                .From("Person JOIN Address ON (Person.AddressId = Address.Id)")
                .Where("Age > @1", 18);
    
        foreach (var person in people)
        {
            Console.WriteLine(person.FirstName);
        }</code></pre>
    

    Methods

    IgnoreQueryFilters()

    Ignores the query filters defined over table by UseQueryFilter in DatabaseConfigurationBase.

    Declaration
    ISelectionQuery<T> IgnoreQueryFilters()
    Returns
    Type Description
    ISelectionQuery<T>

    ISelectionQuery<T> for configuration query.

    Sql(RawSqlString, Object[])

    Create query from sql statement.

    Declaration
    IQueryBase<T> Sql(RawSqlString sql, params object[] args)
    Parameters
    Type Name Description
    RawSqlString sql

    The SQL for executing in server.

    System.Object[] args

    The arguments.

    Returns
    Type Description
    IQueryBase<T>

    Query from sql.

    Remarks

    Sql must be server specific. Because no translation is provide.

    Exceptions
    Type Condition
    System.ArgumentNullException

    if sql is null or white string.

    Sql(FormattableString)

    Create query from sql statement.

    Declaration
    IQueryBase<T> Sql(FormattableString sql)
    Parameters
    Type Name Description
    System.FormattableString sql

    The SQL for executing in server.

    Returns
    Type Description
    IQueryBase<T>

    Query from sql.

    Remarks

    Sql must be server specific. Because no translation is provide.

    Examples
    var id = 15;
    var name = "Name";
    var items = query.Sql($"SELECT * FROM Table WHERE Id = {id} AND Name = {name}");
    Exceptions
    Type Condition
    System.ArgumentNullException

    if sql is null or white string.

    See Also

    IQueryBase<T>
    Back to top KROS a.s.