For an enum with a description I prefer the Ken's solution.
http://nhforge.org/wikis/howtonh/persisiting-described-enums.aspx

<http://nhforge.org/wikis/howtonh/persisiting-described-enums.aspx>For
something more complex I prefer my solution:
http://fabiomaulo.blogspot.com/2009/08/from-db-to-ram-wellknowinstancetype.html

<http://fabiomaulo.blogspot.com/2009/08/from-db-to-ram-wellknowinstancetype.html>

public class CountryType : WellKnowInstanceType<Country>
{
 public CountryType() : base(new Countries(), (e, k) => e.Id == k, e => e.Id) {}
}


2009/8/3 Dmitiry Nagirnyak <[email protected]>

> Hi,
>
> I'm sure it should be simple. How can I assign property (lookup value)
> without a DB roundtrip to obtain ID of the lookup?
>
> // THIS IS WHAT I USED TO DO
> address.Country = Session.Get<Country>(14);
>
>  // THIS IS WHAT DO NOW
> address.Country = PredefinedCountries.Australia;
>
> The last approach work ONLY if the Country has not been loaded into
> Session. NonUniqueObjectException is thrown.
>
> So I have to Evict the object first or just load the actual object (using
> the approach 1).
>
> How can I avoid doing Evict in this case?
>
> And yes, I did override Equals and GetHashCode (even == operators).
>
> I saw custom user type approach:
> http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/08/12/enumeration-classes.aspx
> But it is overkill for my need.
>
> Cheers,
> Dmitriy.
>
> >
>


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