【问题标题】:Fluent nhibernate query where nullable int流利的 nhibernate 查询,其中可为空的 int
【发布时间】:2012-11-27 21:21:28
【问题描述】:

我有一个类似这样的课程:

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

在我加入的查询中,我需要按 WorkTypeID 过滤我的结果

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

它不起作用,因为类型可以为空,我怎样才能使它起作用?

【问题讨论】:

    标签: c# nhibernate fluent-nhibernate fluent


    【解决方案1】:
    query.Where(() => workEntity.WorkTypeID != null && workEntity.WorkTypeID.Value == filter.WorkTypeID.Value);
    

    【讨论】:

    • 如果可能也是这种情况,也可以将 filter.WorkTypeID != null 添加到添加条件中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-26
    • 2011-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-26
    • 2014-09-29
    相关资源
    最近更新 更多