Reference > Operators > Logical

In

  • 2005, 2008, 2012, 2014, 2016, 2017, 2019, 2022

Use the In operation to determine if a value matches any values.

core concept: logical operators

Syntax

{field_expression}.In({listOf} {values})

Arguments

field_expression
An expression representing a field in a database table.
listOf
The values to use for compare against `field_expression`.
values
The items in the array to use for comparison.

Returns

FilterExpression
An expression that can be used anywhere a logical expression can be used:
  • Where clause
  • Join clause
  • Having clause

Prefix the In expression with ! to negate the expression.

Examples

Where Clause

Find all persons where their first name is one of the values in the list

IEnumerable<Person> persons = db.SelectMany<Person>()
    .From(dbo.Person)
    .Where(dbo.Person.FirstName.In("Jane", "John", "Mary", "Joe"))
    .Execute();

Find all persons where their first name is not one of the values in the list

IEnumerable<Person> persons = db.SelectMany<Person>()
    .From(dbo.Person)
    .Where(!dbo.Person.FirstName.In("Jane", "John", "Mary", "Joe"))
    .Execute();

Having Clause

Find product counts by category having a category value in the list

IEnumerable<dynamic> product_counts = db.SelectMany(
        dbo.Product.ProductCategoryType,
        db.fx.Count().As("CategoryCount")
    )
    .From(dbo.Product)
    .GroupBy(dbo.Product.ProductCategoryType)
    .Having(
        dbo.Product.ProductCategoryType.In(
            ProductCategoryType.Books, 
            ProductCategoryType.ToysAndGames, 
            ProductCategoryType.Electronics
        )
    )
    .Execute();

Join Clause

IEnumerable<Person> persons = db.SelectMany<Person>()
    .From(dbo.Person)
    .InnerJoin(dbo.PersonAddress).On(
        dbo.PersonAddress.PersonId.In(1, 12, 14) 
        & 
        dbo.PersonAddress.PersonId == dbo.Person.Id
    )
    .Execute();
Previous
Logical

© 2024 dbExpression. All rights reserved.