Hi 

Sorry to cross post (i posted this question in the nhusers group) but I 
thought I'd get more useful response from the development group as this 
feature is fairly new.

I've got an entity called UserRoleAssociation which implements an interface 
called IDateSpanBoundObject. 

The interface defines 2 properties, ValidFrom and ValidTo which are nullable 
date time properties. 

I've got an extension method as follows... 

public static bool IsCurrent(this IDateSpanBoundObject source) 
{ 
    var currentTime = DateTime.Now.ToUniversalTime(); 


    var result = (source.ValidFrom == null || source.ValidFrom <= 
currentTime) && 
                     (source.ValidTo == null || source.ValidTo >= 
currentTime); 
    return result; 
} 


I've written a HqlGeneratorForMethod which is used when a query contains a 
where clause with this extension. 

Ive got the first part working, my generator gets called when the query is 
executed but I don't know how to get access to the ValidFrom and ValidTo 
properties of the "source" argument which is passed to the expression as 
expressions so that I can create GreaterThan and LessThan tree nodes. 

I've got the following code in my class for accessing the current date but 
how do I get the ValidFrom property expression to do the greater than check 

public override HqlTreeNode BuildHql(MethodInfo method, Expression 
targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder 
treeBuilder, IHqlExpressionVisitor visitor) 
{ 
    var date = DateTime.Now.ToUniversalTime(); 
    Expression<Func<DateTime>> currentDate = () => date; 


    return treeBuilder.GreaterThanOrEqual( 
                visitor.Visit(arguments[0]).AsExpression(), 
                visitor.Visit(currentDate).AsExpression()); 
}

I want to get the value of the argument[0]s ValidFrom property as my 
expression for the "lhs".

Help please.

Thanks
Ben 

Reply via email to