1
什麼會導致此查詢。要開始只投射c
而不填充其子集合ParcelValues
。LINQ to Entities查詢不投影子集合
var result = (from c in _context.Parcels.Include("ParcelValues")
where c.STRAP == strap
select c);
我跑我的應用程序和上面將返回IQueryable<Parcel>
類型的result
對象被填充有正確的記錄屬性Request.ParcelValues
。現在,出於某種原因,無論我如何嘗試使用包含,只會投射包裹字段。
生成的SQL
exec sp_executesql N'SELECT
[Project2].[LAND_AREA] AS [LAND_AREA],
[Project2].[STRAP] AS [STRAP],
[Project2].[SITUS] AS [SITUS],
[Project2].[ZIP_CODE] AS [ZIP_CODE],
[Project2].[MAILING_ADDRESS] AS [MAILING_ADDRESS],
[Project2].[PROPERTY_USE] AS [PROPERTY_USE],
[Project2].[SUBDIVISION] AS [SUBDIVISION],
[Project2].[DSCR] AS [DSCR],
[Project2].[INCORPORATION] AS [INCORPORATION],
[Project2].[SEC_TWP_RGE] AS [SEC_TWP_RGE],
[Project2].[CENSUS] AS [CENSUS],
[Project2].[WATERFRONT] AS [WATERFRONT],
[Project2].[C1] AS [C1],
[Project2].[ID] AS [ID],
[Project2].[STRAP1] AS [STRAP1],
[Project2].[YEAR] AS [YEAR],
[Project2].[LAND] AS [LAND],
[Project2].[IMPROVEMENT] AS [IMPROVEMENT],
[Project2].[JUST] AS [JUST],
[Project2].[ASSESSED] AS [ASSESSED],
[Project2].[TAXABLE] AS [TAXABLE]
FROM (SELECT
[Limit1].[STRAP] AS [STRAP],
[Limit1].[SITUS] AS [SITUS],
[Limit1].[ZIP_CODE] AS [ZIP_CODE],
[Limit1].[MAILING_ADDRESS] AS [MAILING_ADDRESS],
[Limit1].[PROPERTY_USE] AS [PROPERTY_USE],
[Limit1].[SUBDIVISION] AS [SUBDIVISION],
[Limit1].[DSCR] AS [DSCR],
[Limit1].[LAND_AREA] AS [LAND_AREA],
[Limit1].[INCORPORATION] AS [INCORPORATION],
[Limit1].[SEC_TWP_RGE] AS [SEC_TWP_RGE],
[Limit1].[CENSUS] AS [CENSUS],
[Limit1].[WATERFRONT] AS [WATERFRONT],
[Extent2].[ID] AS [ID],
[Extent2].[STRAP] AS [STRAP1],
[Extent2].[YEAR] AS [YEAR],
[Extent2].[LAND] AS [LAND],
[Extent2].[IMPROVEMENT] AS [IMPROVEMENT],
[Extent2].[JUST] AS [JUST],
[Extent2].[ASSESSED] AS [ASSESSED],
[Extent2].[TAXABLE] AS [TAXABLE],
CASE WHEN ([Extent2].[ID] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C1]
FROM (SELECT TOP (1)
[Extent1].[STRAP] AS [STRAP],
[Extent1].[SITUS] AS [SITUS],
[Extent1].[ZIP_CODE] AS [ZIP_CODE],
[Extent1].[MAILING_ADDRESS] AS [MAILING_ADDRESS],
[Extent1].[PROPERTY_USE] AS [PROPERTY_USE],
[Extent1].[SUBDIVISION] AS [SUBDIVISION],
[Extent1].[DSCR] AS [DSCR],
[Extent1].[LAND_AREA] AS [LAND_AREA],
[Extent1].[INCORPORATION] AS [INCORPORATION],
[Extent1].[SEC_TWP_RGE] AS [SEC_TWP_RGE],
[Extent1].[CENSUS] AS [CENSUS],
[Extent1].[WATERFRONT] AS [WATERFRONT]
FROM [dbo].[PARCELS] AS [Extent1]
WHERE [Extent1].[STRAP] = @p__linq__0) AS [Limit1]
LEFT OUTER JOIN [dbo].[PARCEL_VALUES] AS [Extent2] ON [Limit1].[STRAP] = [Extent2].[STRAP]
) AS [Project2]
ORDER BY [Project2].[STRAP] ASC, [Project2].[C1] ASC',N'@p__linq__0 nvarchar(4000)',@p__linq__0=N'0001020003'
是否使用實體框架,或者您使用LINQ到SQL?他們不是一回事! :) – 2013-03-21 20:41:01
對不起。我正在使用Entity Framwork。 – 2013-03-21 20:50:00
查詢明確地從'PARCEL_VALUES'表中選擇字段。你是否確定表中有相關的值? – 2013-03-21 20:53:37