Basic Data Types

Because LINQ to SQL queries translate to Transact-SQL before they are executed on the Microsoft SQL Server. LINQ to SQL supports much of the same built-in functionality that SQL Server does for basic data types.


Implicit or explicit casts are enabled from a source CLR type to a target CLR type if there is a similar valid conversion within SQL Server. For more information about CLR casting, see CType Function (Visual Basic) and as. After conversion, casts change the behavior of operations performed on a CLR expression to match the behavior of other CLR expressions that naturally map to the destination type. Casts are also translatable in the context of inheritance mapping. Objects can be cast to more specific entity subtypes so that their subtype-specific data can be accessed.

Equality Operators

LINQ to SQL supports the following equality operators on basic data types inside LINQ to SQL queries:

  • Equal and Inequality Operator: Equality and inequality operators are supported for numeric Boolean, DateTime, and TimeSpan types. For more about Visual Basic operators = and <>, see Comparison Operators. For more information about C# comparison operators == and !=, see == Operator and != Operator, respectively

  • Is operator: The IS operator has a supported translation when inheritance mapping is being used. It can be used instead of directly testing the discriminator column to determine whether an object is of a specific entity type, and is translated to a check on the discriminator column. For more information about the Visual Basic and C# Is operators, see Is Operator and is.

See Also

SQL-CLR Type Mapping
Data Types and Functions