Applied. People should be aware this only works if your enum is mapped as an
int though... The expression based Where is limited, and I'd recommend
falling back on the string overload whenever things don't work.

On Fri, Aug 28, 2009 at 12:49 PM, James Crowley <[email protected]>wrote:

> Hi guys,
> I encountered a problem using the Where filter on a table, with an Enum:
>
> HasMany(x => x.AuthorAttributes)
>                 .Where(t => t.Type == MetaDataType.Person)
>
> I took a look at the code you're using, and I've got a simple fix that
> appears to work - but to be honest, I'm not that familiar with the
>  expression tree that LINQ creates. In your ExpressionToSql.cs file in
> Utils, I just made the following change:
>
> private static string Convert<T>(Expression<Func<T, object>> expression,
> UnaryExpression body)
> {
>     var constant = body.Operand as ConstantExpression;
>
>     if (constant != null)
>         return Convert(constant);
>
>     var member = body.Operand as MemberExpression;
>
>     if (member != null)
>         return Convert(expression, member);
>     // Begin changes
>     // added processing of unary expression
>     // just simple handling (basically ignoring any Convert nodes that
>     // seem to appear in the tree)
>     var unaryExpression = body.Operand as UnaryExpression;
>     if (unaryExpression != null && unaryExpression.NodeType ==
> ExpressionType.Convert)
>         return Convert(expression, unaryExpression);
>     // End changes
>     throw new NotImplementedException();
> }
>
> Honestly, I don't know the further implications of this, but it seems to
> work fine for Enums anyway!
>
> James
>
> --
> James Crowley
> Managing Director
> Developer Fusion - Connecting developers worldwide
>
> Developer Fusion Ltd | 58 Sandringham Close | Enfield, EN1 3JH
> mob: 07986 624128 web: http://www.developerfusion.com/
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to