如何在linq左连接中处理空表

时间:2018-01-18 07:32:44

标签: c# linq linq-to-sql

我正在编写linq查询,如下所示: -

from eventDetails in CurrentDataContext.EventCarriers
join eventlog in CurrentDataContext.EventLogCarriers on eventDetails.EventID equals eventlog.EventId into hhh
from eventlog in hhh.DefaultIfEmpty()
join quiz in CurrentDataContext.QuizCarriers on eventDetails.EventID equals competition.EventId into aaa
from quiz in aaa.DefaultIfEmpty()

where eventDetails.EventID == eventId && eventDetails.EventStatusId == 1 && eventlog.CreatedBy == userId                                      
group new { eventDetails, quiz, eventlog } by new
{
  eventDetails.EventID,
  eventDetails.Name                                        
} into g
select new VenueModel
{
  Name = g.Key.Name,
  EventId = g.Key.EventID,
  StartDate = g.Key.StartDate,
  EndDate = g.Key.EndDate,
  EventDescr = g.Key.EventDescr,
  EventIconPath = g.Key.EventIconPath,
  EventImagePath = g.Key.EventImagePath,
  Prizes = (from a in g.Select(a => a.competitions)
                  group a by new
                  {
                      a.PrizeId,
                      a.PrizeIconPath,
                      a.CompetitionDescr,
                      a.PrizeImagePath,
                      a.EndDate,
                      a.StartDate,
                      a.Name,
                      a.EventId,
                      a.StatusId
                  } into x

                  select new CCompetitionModel
                  {
                      PrizeDescrption = x.Key.PrizeDescr,
                      PrizeIconPath = x.Key.PrizeIconPath,
                      PrizeId = x.Key.PrizeId,                                                              
                  }).ToList(),
}).FirstOrDefault();

但我收到的错误如强制类型转换为'System.Int32'失败,因为实现的值为null。结果类型的泛型参数或查询必须使用可空类型。

1 个答案:

答案 0 :(得分:0)

task androidSourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.sourceFiles
  }