Looking at D9 source I better understood the situation. Yes, I can use
a custom attribute, no extension method, I have to use a custom user
type, but...

When I save the entity NHibernate knows that access="field" so it uses
the field value to save in database. When I read the entity is the
same, but inverse. So, why it doesn't use the field value to query?

On Jun 15, 10:49 am, CassioT <[email protected]> wrote:
> I was reading the possible solutions presented and:
>
> 1) I think that query.substitution is not right in this case because I
> have a lot of Enumerators in this situation
>
> 2) The User Type solution is better but since I already used the
> DescriptionAttribute to another thing I can't use
> it to match de DB value.
>
> So, Can I create a custom attribute and use it? Maybe with an
> Enumerator extention method? How?
>
> Since I told NHibernate to access the field value, why it uses the
> property value to build the query?
>
> Thank you
>
> On Jun 12, 11:24 pm, Fabio Maulo <[email protected]> wrote:
>
> > Various combination of ways :- first
> > <http://fabiomaulo.blogspot.com/2009/06/database-eliot-ness-of-it.html>
>
> > Thenhttp://nhforge.org/wikis/howtonh/persisiting-described-enums.aspx
>
> > combines, if you need, with
> > <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'  .....
> > what you need ..... </property>
>
> > 2009/6/12 CassioT <[email protected]>
>
> > > Hi again.
>
> > > The application that I work today has to access the database from an
> > > older application. The database schema of this older application has
> > > some fields that act like a flags.
>
> > > Status char(2) - "NA": Not Available, "A": Available, "PA" Partially
> > > Available....
>
> > > I don't like to use them as they are in my app, so what I do is:
>
> > > 1) Create an Enumerator - StatusEnumerator
> > > 2) Map the database field status as string - access="field", private
> > > string status (class)
> > > 3) Create a Property StatusEnumerator Status
>
> > > In step 3, what I do:
>
> > > public StatusEnumerator Status
> > > {
> > >    get
> > >    {
> > >         if(status == "NA")
> > >             return StatusEnumerator.NotAvailable;
> > >             //...
> > >    }
>
> > >    set
> > >    {
> > >         if(value == StatusEnumerator.NotAvailable)
> > >             status = "NA";
> > >         //...
> > >    }
> > > }
>
> > > I already did it some times, it works, but now I found that NH do not
> > > let me filter by these kind of properties.
>
> > > I thought that NH would know that I'm accessing by field and
> > > everything would be ok.
>
> > > What I am doing is wrong, is there  a better way of doing or NH can't
> > > handle this and it's not recommended?
>
> > > Thank you
>
> > --
> > Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
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