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

以上是我想用 LINQ 编写的简单 SQL 查询

我正在使用以下 LINQ 查询,但引发错误:-“转换为值类型 'Int32' 失败,因为具体化值为空。结果类型的泛型参数或查询必须使用可为空的类型。”

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 )
4

2 回答 2

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}
于 2013-05-05T05:45:54.950 回答
0

模型中的 int 应该是 int?,因为可以为 null 的返回值。

于 2013-05-05T07:04:52.633 回答