I'm trying to implement the following
[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 almost have test CanSelectWithGetType using the code below, however,
I haven't figured out where to grab the int at the other end before it
gets to the internal result transformer where it fails casting from
Int to Type:
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 wrong??
--
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.