score:5

Accepted answer

not sure why people always force linq to be one liners.

var entities = context.messagingtemplateentities
                      .where(m => 
                          m.partyid == partyid && 
                          m.messagetemplatetypeid == messagingtemplatetypeid);

if(producttypepartyid != 0)
   entities = entites.where(m.producttypepartyid == producttypepartyid);

decide for yourself which is more readable at a glance.

score:2

use && (m.producttypepartyid == producttypepartyid || producttypepartyid == 0) instead of && m.producttypepartyid == producttypepartyid

score:4

var entities = context.messagingtemplateentities
                      .where(m =>
                          m.partyid == partyid && 
                          m.messagetemplatetypeid == messagingtemplatetypeid &&
                          (producttypepartyid == 0 ? 
                              true : 
                              m.producttypepartyid == producttypepartyid));

Related Query