誰能幫助?我堅持了LINQ查詢我的LINQ查詢..幫助與子查詢
基本上我有一個標準的LINQ查詢,返回場,1場(保險)實際上是另一個LINQ查詢,像這樣
// original from this in etc not included to keep msg short>
select new Models.Custom.House.Insurance()
{
Id = v.IdHouse,
Insurances = from gt in GroupHouseTariffs
join i in InsuranceGroup
on new { gt.IdTariff, gt.IdGroup}
equals
new { i.IdTariff, i.IdGroup}
select new
{
InsuranceId = i.Id,
Price = i.Price
}
基本保險注入從Models.Custom.House保險性質,它的作品,因爲我可以看到它在我調試...我有4條記錄..保險是這樣定義的保險房子基本上是另一個小類的Iqueryable ..
public IQueryable<Insurance> Insurances { get; set;}
所以我試着寫一個擴展方法,像這樣
public static IQueryable<House> WithInsuranceId(this IQueryable<House> qry, int insuranceId)
{
return from h in qry
where h.Insurance .. // BUT here is the problem i don't see my properties, I see plenty of linq methods
}
我應該能夠看到insuranceId和做到這一點,不是嗎?
return from h in qry
where h.Insurance.InsuranceId == 1;
這裏是類(其非常小)
public class Insurance
{
public int? InsuranceId { get; set; }
public float? price{ get; set; }
}
也許有某種特殊的lambda的我需要了解:-)?
任何幫助真的很感激,謝謝。
編譯時錯誤做,如果你居然說'你得到什麼地方h.Insurance.InsuranceId == 1;'? – Ecyrb 2009-10-28 13:08:21
那麼實際上編譯器之前,我看到它在紅色,但如果我編譯 「System.Linq.IQueryable」不包含「InsuranceId」,沒有擴展方法的定義「InsuranceId」接受類型'System.Linq.IQueryable '的第一個參數可以被發現 –
2009-10-28 13:28:32