Fluent nhibernate query where nullable int

2019-08-15 06:44发布

问题:

I have a class similar like this:

public class WorkEntity
{
    ... // other stuff here
    public virtual int? WorkTypeID { get; set; }
}

in my joined queryover I need to filter my results by WorkTypeID

query.Where(() => workEntity.WorkTypeID == filter.WorkTypeID.Value);

it doesn't work, because the type is nullable, how can I make it work?

回答1:

query.Where(() => workEntity.WorkTypeID != null && workEntity.WorkTypeID.Value == filter.WorkTypeID.Value);