правильно не
if (userId == null)
filter = filter1;
а
if (userId.hasValue)
filter = filter1;
filter = userId.hasValue? filter1 : filter2;
filter = x => userId.hasValue?x.UserPtr == userId.Value && x.IsPublished : x.IsPublished
filter = x => x.IsPublished && (userId.hasValue?x.UserPtr == userId.Value : true)