Database Reference
In-Depth Information
Listing 13-14. SQL Generated When let Is Used in the LINQ Query
SELECT
[Extent1].[ReservationId] AS [ReservationId],
[Extent1].[ResDate] AS [ResDate],
[Extent1].[Name] AS [Name]
FROM [Chapter13].[Reservation] AS [Extent1]
WHERE (
(CASE WHEN (@p__linq__0 IS NULL OR
@p__linq__1 = CAST( [Extent1].[ResDate] AS datetime2))
THEN cast(1 as bit)
WHEN ( NOT (@p__linq__0 IS NULL OR
@p__linq__1 = CAST( [Extent1].[ResDate] AS datetime2)))
THEN cast(0 as bit) END) = 1) AND
((CASE WHEN ((@p__linq__2 = @p__linq__3) OR
([Extent1].[Name] LIKE @p__linq__4 ESCAPE N''~''))
THEN cast(1 as bit)
WHEN ( NOT ((@p__linq__2 = @p__linq__3) OR
([Extent1].[Name] LIKE @p__linq__4 ESCAPE N''~'')))
THEN cast(0 as bit) END) = 1)
Listing 13-15 shows the SQL generated from the second query, where we created the conditions inline. This query
is simpler and might execute more efficiently at runtime.
Listing 13-15. Cleaner, More Efficient SQL Generated When Not Using let in a LINQ Query
SELECT
[Extent1].[ReservationId] AS [ReservationId],
[Extent1].[ResDate] AS [ResDate],
[Extent1].[Name] AS [Name]
FROM [Chapter13].[Reservation] AS [Extent1]
WHERE (@p__linq__0 IS NULL OR
@p__linq__1 = CAST( [Extent1].[ResDate] AS datetime2)) AND
((@p__linq__2 = @p__linq__3) OR
([Extent1].[Name] LIKE @p__linq__4 ESCAPE N''~''))
13-5. Making Change Tracking with POCO Faster
Problem
You are using POCO, and you want to improve the performance of change tracking while at the same time minimizing
memory usage. Additionally, you want to implement the Entity Framework Code-First approach.
Solution
Suppose that you have a model with an account and related payments like the one shown in Figure 13-7 .
 
Search WWH ::




Custom Search