I'm not quite sure how a alternate solution would look, could you
elaborate?
I could define the filters in the HBM but that itself wouldn't really
change the design would it?

On 16 Jan, 14:00, Jason Meckley <[email protected]> wrote:
> since you're using HBM, I would define the filters in the HBM mappings
> as well and forgo the code, at least until you understand what's
> happening. you're code works but you need to understand the
> implications of this design decision.  by taking the first address
> from the collection NH will need to load all the addresses for that
> student. A second query. if you were to extract the student address in
> a loop you will create an select n+1 scenario.
>
> On Jan 15, 4:06 pm, Jonas <[email protected]> wrote:
>
> > I'm using HBM mappings. I've tried FNH but I want to learn the
> > "basics" so to speak before I start using FNH. My final solution went
> > like this
>
> > I managed to map StudentAddresses in Student with a filter. To get a
> > fake one-to-one property 'Address' in Student I made a property
> > 'Address' that does:
>
> > Address {
> > get { return this.Addresses.First() }
>
> > Not the best solution perhaps, but it should work since there should
> > always be one Address now in Addresses.
>
> > On 15 Jan, 14:52, Jason Meckley <[email protected]> wrote:
>
> > > try it and see what happens. Are you using FNH or HBM for mappings? I
> > > tried FNH and it works for getting things up and running, but I found
> > > that once I wanted/needed to fine tune the mappings HBM was a better
> > > choice. I also like using HBM to spike mapping features of NH. When I
> > > want to understand what NH can do I strip out all the "noise". any
> > > additional add-ons that are not required are removed.
>
> > > On Jan 15, 2:57 am, Jonas <[email protected]> wrote:
>
> > > > Hi there
>
> > > > and thanks for the links :) In the second link ayende is apparently
> > > > using a technique no longer supported from what I understand. I've
> > > > made some progress since my last post and I've managed to implement
> > > > the interceptor mentioned last in the article. I've also managed to
> > > > apply the filter to the Address class, now I'm trying to add the same
> > > > filter to the Adresses properties in the Student class. This is what I
> > > > got sofar
>
> > > > In the Contextinterceptor:
>
> > > >             if(Context.Current != null)
> > > >             {
> > > >                 session.EnableFilter("customerfilter")
> > > >                     .SetParameter("customerid",
> > > > Context.Current.CustomerId)
> > > >                     .SetParameter("regionalid",
> > > > Context.Current.ReginalId);
> > > >             }
>
> > > > I'm also doing this
>
> > > >             var filterParametersType = new Dictionary<string, IType>
> > > > (1);
> > > >             filterParametersType.Add("customerid",
> > > > NHibernateUtil.Int32);
> > > >             filterParametersType.Add("regionalid",
> > > > NHibernateUtil.Int32);
> > > >             nhCfg.AddFilterDefinition(new FilterDefinition
> > > > ("customerfilter", ":customerid= customeridand :regionalid =
> > > > regionalid", filterParametersType, false));
>
> > > >             foreach (var mapping in nhCfg.ClassMappings)
> > > >             {
> > > >                 if (typeof(IContextAware).IsAssignableFrom
> > > > (mapping.MappedClass))
> > > >                 {
> > > >                     mapping.AddFilter("customerfilter", ":customerid=
> > > > customeridor :regionalid = regionalid");
> > > >                 }
> > > >             }
>
> > > > That seem to be working, however calling Student.Addresses doesn't use
> > > > the filter so from what I understand I need also to filter that
> > > > specific relationship. Preferably I'd rather have a property in the
> > > > Student class to be mapped to a filtered Address, so I can easily call
> > > > Student.Adress. I have no idea how to do that though, don't think you
> > > > can add a filter on a one-to-one relationship, so is that even
> > > > possible?- Dölj citerad text -
>
> > > - Visa citerad text -
-- 
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