In a case like this I would normally pull apart my query logic to keep it easier to read (leave the in-line conditional out of the query itself). To simplify my sample I'm not safely parsing the accountIds, though I'd recommend doing so in your final code (use int.TryParse()
instead).
var missions = db.TDP_Missioni.Where(p => !p.UscitaServizio);
if (objUser.FiltroDipe != null)
{
var accountIds = objUser.FiltroDipe.Split(',').Select(a => int.Parse(a));
missions = missions.Where(m => accountIds.Contains(m.AccountID));
}
var missionCount = missions.Count();
If you prefer to keep this all in a single query, the key portion to look at is accountIds.Contains(m.AccountID)
.
Changing (p.AccountID.ToString() in objUser.FiltroDipe.Split(','))
to objUser.FiltroDipe.Split(',').Contains(p.AccountID.ToString())
should do the trick, though I'd really recommend dealing with integers instead of strings.