Excluding / Including fields and prefetch paths dont work with Entity Instances in projections

Posts   
 
    
TomDog
User
Posts: 623
Joined: 25-Oct-2005
# Posted on: 24-Oct-2012 12:26:04   

This (northwind in LINQPad, adapter)

from p in Product.IncludeFields(p=>p.ProductName).WithPath(p1=>p1.Prefetch(p=>p.Category))
select p

produces this

SELECT [LPA_L1].[CategoryID] AS [CategoryId],
  [LPA_L1].[ProductID] AS [ProductId],
  [LPA_L1].[ProductName],
  [LPA_L1].[SupplierID] AS [SupplierId]
FROM
 [dbo].[Products]  [LPA_L1]  

DECLARE @p1 Int; SET @p1=6
DECLARE @p2 Int; SET @p2=2
DECLARE @p3 Int; SET @p3=7
DECLARE @p4 Int; SET @p4=4
DECLARE @p5 Int; SET @p5=8
DECLARE @p6 Int; SET @p6=1
DECLARE @p7 Int; SET @p7=5
DECLARE @p8 Int; SET @p8=3
SELECT [dbo].[Categories].[CategoryID] AS [CategoryId],
  [dbo].[Categories].[CategoryName],
  [dbo].[Categories].[Description],
  [dbo].[Categories].[Picture]
FROM
 [dbo].[Categories]  
WHERE
 ( [dbo].[Categories].[CategoryID] IN (@p1,
  @p2,
  @p3,
  @p4,
  @p5,
  @p6,
  @p7,
  @p8))

but this

from p in Product.IncludeFields(p=>p.ProductName).WithPath(p1=>p1.Prefetch(p=>p.Category))
select new {p}

produces

SELECT [LPLA_1].[CategoryID] AS [CategoryId],
  [LPLA_1].[Discontinued],
  [LPLA_1].[ProductID] AS [ProductId],
  [LPLA_1].[ProductName],
  [LPLA_1].[QuantityPerUnit],
  [LPLA_1].[ReorderLevel],
  [LPLA_1].[SupplierID] AS [SupplierId],
  [LPLA_1].[UnitPrice],
  [LPLA_1].[UnitsInStock],
  [LPLA_1].[UnitsOnOrder]
FROM
 [dbo].[Products]  [LPLA_1]  

No include fields, no prefetch - why is that?

SD.LLBLGen.Pro.LinqSupportClasses.NET35.dll version 3.5.12.0807 SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll version 3.5.12.0824

Jeremy Thomas
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 24-Oct-2012 12:46:02   

Because the result isn't an entity query but a projection to an anonymous type. Prefetch paths therefore don't work at all in that situation, and neither do include/exclude fields, as it's not an entity query but a projection (the result objects are anonymous typed objects with 1 member, not the entity itself).

Frans Bouma | Lead developer LLBLGen Pro