entity framework - how to debug EF 5 null reference exception? -


i getting null refrence exception when im filtering ef absolultely clueless.

enter image description here

public ienumerable<tonalitybatchmodel> gettonalitybatch(int briefid) {     try     {         var brief = neptuneunitofwork.briefs.findwhere(b => b.id == briefid).firstordefault();          if (brief != null && brief.tonalitycriteria != null)                     {                         return brief.tonalitycriteria.tonalitybatches                                     .select(b => new tonalitybatchmodel()                                         {                                             briefid = b.briefid,                                             status = b.tonalitycriteria.isactive == true ?"active":"ended",                                             batchid = b.id,                                             competitorid = b.briefcompetitorid,                                             competitor = brief.briefcompetitors.where(i=>i.id == b.briefcompetitorid).select(c=>c.organisation.name).first(),                                             size = b.batchsize,                                             startdate = b.startdate,                                             enddate = b.enddate,                                             ispublished = b.lookup_tonalitybatchstatus.id == (int)tonalitybatchstatus.published?"yes":"no",                                             iscompleted = b.lookup_tonalitybatchstatus.id == (int)tonalitybatchstatus.completed ? "yes" : "no",                                             isassigned = b.lookup_tonalitybatchstatus.id == (int)tonalitybatchstatus.allocated ? "yes" : "no",                                             importantcount = b.tonalityitems.count(i=> i.isimportant),                                             articlescount = b.tonalityitems.count,                                             favourablecount = b.tonalityitems.count(i => i.lookup_tonalityscoretypes.id ==(int)tonalitysourcetype.favourable),                                             unfavourablecount = b.tonalityitems.count(i => i.lookup_tonalityscoretypes.id ==(int)tonalitysourcetype.unfavourable),                                             neutralcount = b.tonalityitems.count(i => i.lookup_tonalityscoretypes.id ==(int)tonalitysourcetype.neutral)                                          }).tolist();                     }                      return new list<tonalitybatchmodel>();              }             catch (exception ex)             {                 logger.error(ex);                 throw;             }         } 

you'll need reduce query simpler query, , start building again until nullreferenceexception occurs. looking @ code, here places (i'm making assumptions since don't know model):

competitor = brief.briefcompetitors.where(i=>i.id == b.briefcompetitorid).select(c=>c.organisation.name).first() 

briefcompetitors null. c.organisation null.

ispublished = b.lookup_tonalitybatchstatus.id == (int)tonalitybatchstatus.published?"yes":"no", 

(and other similar lines) b.lookup_tonalitybatchstatus might null.

importantcount = b.tonalityitems.count(i=> i.isimportant), 

(and other similar lines) b.tonalityitems might null.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -