c# - Fluent NHibernate Where on Empty String -
i'm applying .where()
-restriction on iqueryover<t,t>
in fluentnh, such:
.where(x => x.col1 == null || x.col1 == "");
which generates following sql:
where (col1 null or col1 = null)
how can make nh understand empty string means empty string?
you can write where
clause this:
.where(restrictions.on<classtype>(obj => obj.col1).isnull || restrictions.on<classtype>(obj => obj.col1).islike(@""))
alternatively, if you're doing on several queries should consider creating query extension:
public static class queryextention { public static iqueryover<e, f> wherestringisnullorempty<e, f>(this iqueryover<e, f> query, expression<func<e, object>> expression) { var property = projections.property(expression); var criteria = restrictions.or(restrictions.isnull(property), restrictions.eq(property, string.empty)); return query.where(criteria); } }
then should able create like:
.queryover<classtype>() .wherestringisnullorempty(obj => obj.col1)
Comments
Post a Comment