Database Reference
In-Depth Information
Listing 16-12. Parameterization and data types: C# code
/* Using constant */
var q = context.Customers.Where(t => t.CreditLimit > 200)
.Select(t => t.FirstName);
/* Using Int64 */
long i64 = 200;
var q = context.Customers.Where(t => t.CreditLimit > i64)
.Select(t => t.FirstName);
/* Using Int */
int i32 = 200;
var q = context.Customers.Where(t => t.CreditLimit > i32)
.Select(t => t.FirstName);
/* Using byte */
byte b = 200;
var q = context.Customers.Where(t => t.CreditLimit > b)
.Select(t => t.FirstName);
Listing 16-13 shows auto-generated SQL. As you can see, constant values from the client code are not
parameterized. In the case of variables, Entity Framework uses either the data type of the variables or the property
from the class, choosing the type with the larger range of domain values and precision.
Listing 16-13. Parameterization and data types: Generated SQL
-- Constant
SELECT [Extent1].[FirstName] AS [FirstName]
FROM [dbo].[Customers] AS [Extent1]
WHERE [Extent1].[CreditLimit] > 200 '
-- Int64
exec sp_executesql N'SELECT
[Extent1].[FirstName] AS [FirstName]
FROM [dbo].[Customers] AS [Extent1]
WHERE [Extent1].CreditLimit > @p__linq__0'
,N'@p__linq__0 bigint',@p__linq__0=200
-- Int32
exec sp_executesql N'SELECT
[Extent1].[FirstName] AS [FirstName]
FROM [dbo].[Customers] AS [Extent1]
WHERE [Extent1].CreditLimit > @p__linq__0'
,N'@p__linq__0 int',@p__linq__0=200
-- byte
exec sp_executesql N'SELECT
[Extent1].[FirstName] AS [FirstName]
FROM [dbo].[Customers] AS [Extent1]
WHERE [Extent1].CreditLimit > @p__linq__0'
,N'@p__linq__0 int',@p__linq__0=200
 
Search WWH ::




Custom Search