Hi,
I am trying to map an enumeration class (something similar to Jimmy
Bogard's idea here:
http://lostechies.com/jimmybogard/2008/08/27/strategies-and-discriminators-in-nhibernate/.
One difference is that in my scenario, my PricingStrategy class is
implemented like this (notice I do not have separate subclasses for
each PricingStrategy):
public class PricingStrategy : Enumeration<PricingStrategy>
{
public static readonly PricingStrategy FullPrice = new
PricingStrategy(1, "Full price");
public static readonly PricingStrategy LowStock = new
PricingStrategy(2, "Low stock");
public int Id { get; protected set; }
public string Name { get; protected set; }
protected PricingStrategy(int id, string name)
{
// omitted
}
// overrides of Equals, GetHashCode, ==, and != omitted
}
With my current mappings, I get a NonUniqueObjectException. I am
fairly certain that this is because:
var fromSession =
session.Get<PricingStratey>(PricingStrategy.FullStock.Id);
Console.WriteLine(object.ReferenceEquals(fromSession,
PricingStrategy.FullStock); // prints false
I end up with two different objects that are really the same loaded
because sometimes the session loads these objects, and sometimes I
want to explicitly reference on of them via the public static
properties (in my core domain classes, I don't have access to the
session).
So far my best shot has been to create an IUserType, but I am
struggling with correctly implementing NullSafeGet(). I haven't even
tried NullSafeSet yet (not sure if I will need to since these types
are immutable).
In case it helps, I am using NHibernate 3.2 and mapping by code.
My questions are:
1. Is this possible?
2. Is there a better way to do this than with an IUserType?
3. If IUserType is the best way to do this, I need some pointers w/
NullSafeGet (and probably a few other methods as well).
Thanks,
Chris B
--
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.