2014-10-23 3 views
1

dapper를 사용 중입니다. splitOn 함수를 구현하여 AdListingSearchResult에 설정된 위치 개체를 가져 왔지만 하위 쿼리 (MainPhotoFileName 및 TotalPhotos)가 이제 null과 0이됩니다. 내가 여기서 뭘 잘못하고 있는거야?dapper의 하위 쿼리가 더 이상 작동하지 않습니다.

var data = GetConnection().Query<AdListingSearchResult, AdListingLocationSearchResult, AdListingSearchResult>(@" 
SELECT TOP 10 a.AdListingID, a.Title, a.Details, a.CreateDateTime, l.LocationID, l.CountryID, l.USCity, l.USStateCode, l.IntlRegion, c.CountryName, 
(SELECT TOP 1 ap.Filename FROM tbAdListingPhotos ap WHERE ap.AdListingID = a.AdListingID) AS MainPhotoFileName, 
(SELECT COUNT (*) FROM tbAdListingPhotos ap WHERE ap.AdListingID = a.AdListingID) AS TotalPhotos 
FROM tbAdListing a 
INNER JOIN tbLocation l ON (a.LocationID = l.LocationID) 
INNER JOIN tbEnumCountry c ON (l.CountryID = c.CountryID) 
WHERE a.Deleted = 0 ORDER BY a.CreateDateTime DESC     
", (a, l) => 
{ 
    a.Location = l; 
    return a; 
}, 
splitOn: "LocationId" 
).AsQueryable(); 

return data; 
+0

어떤 물체은'MainPhotoFileName' (등) 특성을 가지고? 'AdListingSearchResult'? 또는 'AdListingLocationSearchResult'? –

답변

1

나는이 하위 쿼리가 AdListingSearchResult 객체의 속성에 매핑하기위한 것입니다 같은데요. 그러나 행은 splitOn 매개 변수에 따라 가로로 분할되어 있으므로 AdListingSearchResult에는 해당 값이 표시되지 않습니다.

당신은 단순히 SQL을 재정렬 할 수 있어야한다 :

SELECT TOP 10 a.AdListingID, a.Title, a.Details, a.CreateDateTime, 
(SELECT TOP 1 ap.Filename FROM tbAdListingPhotos ap WHERE ap.AdListingID = a.AdListingID) AS MainPhotoFileName, 
(SELECT COUNT (*) FROM tbAdListingPhotos ap WHERE ap.AdListingID = a.AdListingID) AS TotalPhotos, 
l.LocationID, l.CountryID, l.USCity, l.USStateCode, l.IntlRegion, c.CountryName 
FROM tbAdListing a 
... 
+0

나는 실제로 그것에 대해 생각하고있었습니다. 나는 그에게 총을주고 곧보고 할 것이다. 감사! – TheWebGuy

+0

그게 전부 였어, 고마워. 방금 선택한 선언문을 재정렬해야했습니다. – TheWebGuy

관련 문제