you define the filter once, but you will need to include it with for
any mapping that would be effected by the filter. for example
<filter-def name="IsActive" condition="Active = :active" />
<param name="active" type="bool" />
</filter-def>
<class name="Customer">
...
<filter name="IsActive" />
</class>
here is an example of overriding the condition
<class name="Order">
...
<filter name="IsActive" condition="Invoiced != :active" />
</class>
this is all from memory, so there are probably errors, but that's the
idea anyway.
usage would look like this:
session.EnableFilter("IsActive").SetParameter("active", true);
var activeCustomers = session.CreateQuery("from
Customer").List<Customer>();
var openOrders = session.CreateQuery("from Order").List<Order>();
session.DisableFilter("IsActive");
var AllCustomers = session.CreateQuery("from
Customer").List<Customer>();
which would produce sql
select * from Customer where Active = 1
select * from Order where Invoiced <> 1
select * from Customer
On Aug 13, 10:19 am, Diego Mijelshon <[email protected]> wrote:
> I believe you can do it just once.
>
> Diego
>
> On Fri, Aug 13, 2010 at 11:15, rhartzog <[email protected]> wrote:
> > Thanks Diego,
>
> > One thing that is unclear in the documentation: I assume the answer is
> > yes, but just making sure, do you have to define a filter in each
> > mapping file or can you define it in one mapping file and reference it
> > from any other mapping file?
>
> > On Aug 13, 8:57 am, Diego Mijelshon <[email protected]> wrote:
> > > Ryan,
>
> > > You might want to look into Filters instead:
> >http://nhforge.org/doc/nh/en/index.html#filters
>
> > > Diego
>
> > > On Fri, Aug 13, 2010 at 09:25, rhartzog <[email protected]> wrote:
> > > > I hear you Dan, that is how I currently do it, just makes it messy. If
> > > > I need to get a related collection through lazy loading I have to
> > > > filter the children which adds more stink. .children().where(c =>
> > > > c.IsDeleted == false) just gets a bit redundant. I was hoping to just
> > > > specify when I DO want them since that happens in far fewer locations
> > > > of the code.
>
> > > > Appreciate the suggestion,
> > > > Ryan
>
> > > > On Aug 13, 3:57 am, Dan B <[email protected]> wrote:
> > > > > I handle IsDeleted filtering in my Repositories for this reason.
>
> > > > > On Aug 12, 4:50 pm, rhartzog <[email protected]> wrote:
>
> > > > > > Alright, thank you Jason.
>
> > > > > > On Aug 12, 10:40 am, Jason Meckley <[email protected]> wrote:
>
> > > > > > > I don't think you can override the where clause. if you need
> > > > > > > conditional criteria i would go with explicit queries/criteria
> > > > objects
> > > > > > > or filters.
>
> > > > > > > On Aug 12, 10:49 am, rhartzog <[email protected]> wrote:
>
> > > > > > > > When using the where filter on the mapping file is it possible
> > to
> > > > > > > > override this? If I want to list the deleted entities to an
> > admin
> > > > so
> > > > > > > > he/she can reactivate it. Is this possible? I saw comments
> > from
> > > > > > > > Gabriel in his soft delete post that say it is not, but that
> > was
> > > > from
> > > > > > > > 2008 and thought I would see if anything has changed.
>
> > > > > > > > Thank you
>
> > > > --
> > > > 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]<nhusers%[email protected]>
> > <nhusers%[email protected]<nhusers%[email protected]>>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/nhusers?hl=en.
>
> > --
> > 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]<nhusers%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.
>
>
--
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.