我正在尝试使用linq谓词生成过滤器代码。当我使用带有对象的谓词时!= null:
public static Expression<Func<ContactPermitsSearch, bool>> PermitNumberNotNull()
{
Expression<Func<ContactPermitsSearch, bool>> predicate = contactPermit => contactPermit.PermitNumber != null;
return predicate;
}
由以下人员调用:
public static IQueryable<ContactPermitsSearch> FilterByNameMailingPermit(this IQueryable<ContactPermitsSearch> queryable, string search, bool filterOn)
{
var predicate = PredicateBuilder.True<ContactPermitsSearch>();
predicate = predicate.And(PermitNumberNotNull());
var filtered = queryable.AsExpandable().Where(predicate);
return filtered;
}
生成的SQL语句不包含PermitNumberNotNull谓词语句。
关于解决这个问题的想法?
答案 0 :(得分:0)
代码没有明显的错误。我确定如果在将predicate
与PermitNumberNotNull()
合并之后检查调试器中的contactPermit.PermitNumber
,您将看到非空谓词是表达式树的一部分。
唯一合理的假设是EF知道class SimSpout(storm.Spout):
# Not much to do here for such a basic spout
def initialize(self, conf, context):
## Open the file with read only permit
self.f = open('data.txt', 'r')
## Read the first line
self._conf = conf
self._context = context
self._offset = 0
storm.logInfo("Spout instance starting...")
# Process the next tuple
def nextTuple(self):
# check if it reach at the EOF to close it
with open(self.f) as f:
f.readlines()[self._offset]
#Emit a random sentence
storm.logInfo("Emiting %s" % line)
storm.emit([line])
self._offset = self._offset + 1
无法成为null,因为它的必需属性。因此,它只是忽略谓词。