2013-05-05 37 views
1
select a.stakebuyinid , a.StakeBuyInValue from StakeBuyInByStakeCategories AS b 
left join StakeBuyIns AS a on b.stakebuyinid = a.stakebuyinid 
where b.GametypeId = 1 and b.StakeCategoryID = 3 and a.Currencyid = 1 

以上是我簡單的SQL查詢我想在LINQ寫作留在LINQ連接查詢

我使用下面的LINQ查詢,但引發錯誤: - 「演員價值型‘的Int32’失敗,因爲物化值爲null。結果類型的泛型參數或查詢必須使用可空類型。「

var query = (from v in db.StakeBuyInByStakeCategories.Where(x => x.GameTypeId == gametypeid && x.StakeCategoryId == stakecategoryid) 
         join u in db.StakeBuyIns.Where(y => y.CurrencyId == currencyid) 
           on v.StakeBuyInId equals u.StakeBuyInId into Temp 
          from vus in Temp.DefaultIfEmpty() 
         select new { 
          vus.StakeBuyInId, 
          vus.StakeBuyInValue) 
+0

好的。你嘗試了什麼,問題在哪裏? – Artless 2013-05-05 05:31:00

+0

我編輯我的問題 – ujjaval 2013-05-05 05:46:21

回答

1

假設
StakeBuyInByStakeCategoriesList as IEnumerable<StakeBuyInByStakeCategories>StakeBuyInsList as IEnumerable<StakeBuyIns>

(from b in StakeBuyInByStakeCategoriesList 
from a in StakeBuyInsList  
.Where(b.stakebuyinid equals a.stakebuyinid) 
.DefaultIfEmpty()  
.Where(b.GametypeId == 1 and b.StakeCategoryID == 3 and a.Currencyid == 1)  
select new {Stakebuyinid=a.stakebuyinid, StakeBuyInValue=a.StakeBuyInValue} 
+0

不工作:(Sysntax錯誤 – ujjaval 2013-05-05 06:15:56

+0

我已更新答案朋友。 – 2013-05-05 06:31:37

0

在你的模式應該是一個int通過int?因爲可空的返回值是可能的。