views:

55

answers:

1

I have a collection of entities with an any-association, like this:

public class CreatedLog
{
    public string Message { get; set; }
    public EntityBase CreatedEntity { get; set; } // an association to any entity
}

Is there a way - through HQL or Criteria API - to find only the log entries, that are for a specific entity-type?

Like

session.CreateCriteria<CreatedLog>()
.Add(Restriction.Eq("CreatedEntityType", "Note"));
+1  A: 

You could use the special class property:

from CreatedLog c where c.CreatedEntity.class = 'YourSpecificClass'
Darin Dimitrov
Nice! That's looks like a way to go. Do you know if it has an eqvivalent in the criteria api?
asgerhallas
Oops. It works out of the box. I mistyped.
asgerhallas
@asgerhallas, I don't know if this is possible with Criteria API. Maybe someone could bring more insight.
Darin Dimitrov
I just did it like this: Restriction.Eq("CreatedEntity.class", "YourSpecificClass")
asgerhallas
@asgerhallas, that's great, didn't know this was possible. Thanks.
Darin Dimitrov