Hey,

All this works. BUT only if the lookup has not already been loaded into
session.
If it is loaded and I'm trying to use the static value it fails with
NonUniqueObjectException.

So before setting the value to the object I have to Evict it first:

session.Evict(address.Country)
address.Country = Countries.Australia

Does not look any good :(

I am not sure how I can avoid this :(

Any ideas?

Cheers,
Dmitriy.
2009/7/30 Nexus <[email protected]>

>
> No problem does not have to go to the database to get the country :)
>
> On 30 jul, 09:42, Dmitiry Nagirnyak <[email protected]> wrote:
> > Thanks a lot for the reply.
> >
> > I'll give it a try.
> >
> > Should the code like this still work correctly with NH:
> > address.Country = Countries.Austalia
> > Session.Update();
> > Session.Flush();
> >  address.Country = Countries.Germany
> > Session.Update();
> > Session.Flush();
> >
> > Assert.AreSame(Countries.Germany, address.Country)
> >
> > Cheers.
> >
> > 2009/7/30 Nexus <[email protected]>
>  >
> >
> >
> >
> >
> > > Hey
> >
> > > At first set your id to assigned, use guid or something like that.
> >
> > > Second overload your Equals, gethashcode, (use id as equalifier) ,
> > > also overload operators
> >
> > > Then create a static class countries
> >
> > > public static class Countries
> > > {
> >
> > > public readonly static Country Australia = new Country
> > > ("EF989B65-1714-4e51-BAC2-D1766CA15A2C", "Australia");
> >
> > > // Optional
> >
> > > public static IEnumerable<Country> All
> > > {
> > >  get
> > >  {
> > >    yield return Australia;
> > >    // ...
> > >  }
> > > }
> >
> > > }
> >
> > > Kind Regards , remember assigned id's cannot be used with
> > > saveorupdate, only save !!!
> >
> > > On 30 jul, 07:20, Dmitiry Nagirnyak <[email protected]> wrote:
> > > > Anybody please?
> >
> > > > 2009/7/29 Dmitiry Nagirnyak <[email protected]>
> >
> > > > > Hi,
> >
> > > > > I would like to use code like this for my lookup classes:
> >
> > > > > if (address.Country == Countries.Australia)
> > > > > {
> > > > >   // Do something
> > > > > }
> >
> > > > > Here the Countries class is defined like this:
> > > > > public class Countries
> > > > > {
> > > > >   public Country Austrlia
> > > > >   {
> > > > >     get
> > > > >     {
> > > > >       return ObtainLokupFromDB("Australia");
> > > > >       // OR
> > > > >       return new Country
> > > > >       {
> > > > >           Id = 14,
> > > > >           Code = "Australia",
> > > > >           Description = "Australia"
> > > > >       }
> > > > >     }
> > > > > }
> >
> > > > > But I am not sure hot to implement this.
> > > > > On one hand I don't want to go to the database as I know all the
> values
> > > > > even at compile time.
> > > > > But if I'll create a Country instance it won't allow me to use "=="
> > > > > operator to compare teh values (so I need to override Equals and
> > > > > GetHashCode).
> >
> > > > > What are your suggestions on this?
> >
> > > > > Cheers,
> > > > > Dmitriy.- Tekst uit oorspronkelijk bericht niet weergeven -
> >
> > > > - Tekst uit oorspronkelijk bericht weergeven -- Tekst uit
> oorspronkelijk bericht niet weergeven -
>  >
> > - Tekst uit oorspronkelijk bericht weergeven -
> >
>

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