I am getting started with LINQ and NHibernate, can you help me get oriented please:
I need to pass a lambda statement to nhibernate .QueryOver() which is conditional based on a property on my model:
if (model.PropertyA != String.Empty) {
var searchResults = nhibSession.QueryOver<type>(x =>
x.propA == model.PropertyA)
.List();
}
Is there a better way to do this using a C# Expression instead of a lambda statement? How do I create an Expression using model.PropertyA? Do I use Expression.Property() or Expression.Field()?
thanks
I suspect you should be using
Expression.Constant– even though it doesn’t “feel” like a constant in the normal sense, it’s constant for that expression as the model isn’t part of the input to the expression.