Hello,

I'm currently trying to implement a soft-delete feature in our entity
classes.

I already saw the post about Contextual Data in (http://nhforge.org/
wikis/howtonh/contextual-data-using-nhibernate-filters.a
spx) and I was successfull at adding the following filter:

----
var filterParametersType = new Dictionary<string, IType> {{"active",
NHibernateUtil.Boolean}}; configuration.AddFilterDefinition(new
FilterDefinition("isActive", "(IsActive is null OR :active =
IsActive)", filterParametersType));

foreach (var mapping in configuration.ClassMappings) {
        if (typeof (EntityWithAccess).IsAssignableFrom(mapping.MappedClass))
                mapping.AddFilter("isActive", "(IsActive is null OR :active =
IsActive)"); }

----
In my SessionFactoryHolderFactory I have:
public class IMSSessionFactoryHolder : ISessionFactoryHolder {
        (...)
        public ISession CreateSession(Type type)
        {
                var ret = _sessionFactoryHolder.CreateSession(type);
                if (typeof(EntityWithAccess).IsAssignableFrom(type))
 
ret.EnableFilter("isActive").SetParameter("active", true);

                return ret;
        }
}
----
<?xml version="1.0" encoding="utf-16"?>
<hibernate-mapping  auto-import="true" default-lazy="false"
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns="urn:nhibernate-mapping-2.2">
  <class name="DoisSoft.Core.Data.Person, DoisSoft.Core.Data"
table="CO_Person" dynamic-update="true" dynamic-insert="true"
batch-size="50" lazy="true">
    <id name="Id" access="property" column="Id" type="Guid"
unsaved-value="00000000-0000-0000-0000-000000000000">
      <generator class="guid.comb">
      </generator>
    </id>
(...)
    <many-to-one name="Language" access="property"
class="DoisSoft.Core.Data.Language, DoisSoft.Core.Data"
column="LanguageId"
fetch="join" lazy="proxy" />
    <one-to-one name="Profile" access="property"
class="DoisSoft.Core.Data.Profile, DoisSoft.Core.Data" />
  </class>
</hibernate-mapping>
----

If I do a "from Person" I can see that the filter is applied to both
the Language and Profile (and this is great!!) but there isn't a
filter for the Person entity.

SELECT (...) FROM CO_Person persons0_ left outer join CO_Language
language1_ on persons0_.LanguageId=language1_.Id left outer join
CO_Profile profile2_ on persons0_.Id=profile2_.Id WHERE
(language1_.IsActive is null OR @p0 =
language1_.IsActive) and (profile2_.IsActive is null OR @p1 =
profile2_.IsActive); @p0 = True, @p1 = True

Also, I would like this behaviour to be applied to a lazy-loaded
collection of Person. Is this possible??


With kindest regards
Carlos Sobrinho

-- 
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