I'm trying to implement the following (test cases below)

        [Test]
        public void CanGetTypeWhere() {
            // what about dynamic type checking?  OfType is generic
and won't allow for it
            var query = (from o in session.Query<Animal>()
                         where o.GetType() == typeof(Dog)
                         select o).ToList();

            Assert.AreEqual(2, query.Count);
        }

        [Test]
        public void CanSelectWithGetType()
        {
            var query = (from o in session.Query<Animal>()
                         select new {
                             Id = o.Id,
                             Type = o.GetType()
                         }).ToList();

            Assert.Greater(0, query.Count);
        }

I've almost got test #2 working using the following, however, I can't
figure out who to intercept the Int to Type cast at the other end.  It
fails at the result transformer at the moment:


        private FunctionRegistry()
        {
            // TODO - could use reflection here
            Register(new QueryableGenerator());
            Register(new StringGenerator());
            Register(new DateTimeGenerator());
            Register(new ICollectionGenerator());
            RegisterMethodGenerator(
                ReflectionHelper.GetMethod((object o) => o.GetType()),
                new GetTypeGenerator()
            );
        }

    public class GetTypeGenerator : BaseHqlGeneratorForMethod
    {
        public GetTypeGenerator()
        {
            SupportedMethods = new [] {
                ReflectionHelper.GetMethod<object>(o => o.GetType())
            };
        }

        public override HqlTreeNode BuildHql(MethodInfo method,
Expression targetObject, ReadOnlyCollection<Expression> arguments,
HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
        {
            return treeBuilder.Dot(
                visitor.Visit(targetObject).AsExpression(),
                treeBuilder.Class()
            );
        }
    }


Perhaps I am going about this the wrong way!?  Any suggestions?



-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en.

Reply via email to