Trying to use QueryOver and a flagged enum query. This works in Nhibernate.Linq:
var results = repo.Query()
.Where(x => (x.Classification & LineItemClassification.Shipping) == LineItemClassification.Shipping);
This throws Could not determine member from (Convert(x.Classification) & 2)
using QueryOver:
var results = repo.QueryOver()
.Where(x => (x.Classification & LineItemClassification.Shipping) == LineItemClassification.Shipping);
Any ideas? Suggestions?
Enum:
[Flags]
public enum LineItemClassification
{
Foo,
Widget,
Shipping
}
Mapping:
Map(x => x.Classification)
.CustomType<LineItemClassification>();
I ran into a similar issue today and ended up doing a SQL projection. Not ideal, as it moves us away from the type safety that we get with the QueryOver API, but it works. The relevant portion of my code follows.
.QueryOver<ProjectActivity>()
.Where(Expression.Gt(Projections.SqlProjection(String.Format("({{alias}}.ProjectActivityTypeId & {0}) as ProjectActivityTypeId", (int)type), null, null), 0))
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With