tags:

views:

28

answers:

1
        ICriteria iCriteria = DataAccessHelper.GetSession().CreateCriteria(typeof(T))
            .Add(Expression.Lt("Id", InitialIndex))
            .Add(Expression.Eq("Member", member))
            .Add(Expression.Eq("Action.class", typeof(U)))
            .SetMaxResults(MaxResult)
            .AddOrder(Order.Desc("Id"));

I basically wanna create a criteria that can filter the Action object by his implement class. But when I run this throws the following exception.

{"could not resolve property: Action.class of: Classes.MemberAction"}

The class MemberAction contains:

public class MemberAction {

   Int64 Id;
   Member member;
   Action action;
   IDictionary<string,string> Attributes;
   etc.....
}

and the class Action is the base of 4 other classes

A: 
.Add(Expression.Lt("Id", InitialIndex))
.Add(Expression.Eq("Member", member))
.CreateAlias("Action", "Action") //here's the magic
.Add(Expression.Eq("Action.class", typeof(U)))
.SetMaxResults(MaxResult)
.AddOrder(Order.Desc("Id"))

Criteria queries work on an implicit alias. They don't dereference relationships automatically.

The added line creates an alias called "Action" (second parameter, could be anything you want to name it) on the projected property "Action".

The next statement now refers to the class pseudo-property of entity referenced by the "Action" alias.

Diego Mijelshon
Thanks man, this works great
firematta