NHibernate.Mapping.Attributes: Pass UnsavedValue as object
Description
I'd like to propose a simple improvement for NHibernate.Mapping.Attributes.
Consider the code at the end. I defines an abstract, generic domain object, which allows for specifying the type of its ID. What I'd like to do is the following:
UnsavedValue = default(IdT)
Beside constants and typeof this is the only thing I can use to define values in attributes. However, this doesn't work because UnsavedValue only accepts a string.
I propose to either change the DefaultValue property to object type so that I can pass non-string constants. Internally the mapping code generator would simply call .ToString().
If I get a short explanation how to modify the files of which all the mapping attributes are generated I'd be willing to do it myself.
Thanks for the consideration,
Christoph
public abstract class GenericDomainObject<IdT> where IdT : struct { private IdT m_Id = default(IdT);
/// <summary> /// ID may be of type string, int, custom type, etc. /// </summary> [Id(0, Name = "ID", Column = "ID", TypeType = typeof(Int32), AccessType = typeof(PascalCaseMUnderscoreStrategyFieldAccessor))] public virtual IdT ID { get { return m_Id; } }
/// <summary> /// Transient objects are not associated with an item already in storage. For instance, /// a <see cref="User" /> is transient if its ID is 0. /// </summary> public bool IsTransient() { return (m_Id.Equals(default(IdT))); } }
Environment
None
Activity
Show:
Pierre Henri Kuaté June 24, 2006 at 9:09 AM
I have added UnsavedValueObject.
Pierre Henri Kuaté June 16, 2006 at 9:54 AM
I will work on this in few days; if there is no special issue, it should be done before the 1.2.0.Alpha2 is released.
I'd like to propose a simple improvement for NHibernate.Mapping.Attributes.
Consider the code at the end. I defines an abstract, generic domain object, which allows for specifying the type of its ID. What I'd like to do is the following:
UnsavedValue = default(IdT)
Beside constants and typeof this is the only thing I can use to define values in attributes. However, this doesn't work because UnsavedValue only accepts a string.
I propose to either change the DefaultValue property to object type so that I can pass non-string constants. Internally the mapping code generator would simply call .ToString().
If I get a short explanation how to modify the files of which all the mapping attributes are generated I'd be willing to do it myself.
Thanks for the consideration,
Christoph
public abstract class GenericDomainObject<IdT>
where IdT : struct
{
private IdT m_Id = default(IdT);
/// <summary>
/// ID may be of type string, int, custom type, etc.
/// </summary>
[Id(0, Name = "ID", Column = "ID", TypeType = typeof(Int32),
AccessType = typeof(PascalCaseMUnderscoreStrategyFieldAccessor))]
public virtual IdT ID
{
get { return m_Id; }
}
/// <summary>
/// Transient objects are not associated with an item already in storage. For instance,
/// a <see cref="User" /> is transient if its ID is 0.
/// </summary>
public bool IsTransient()
{
return (m_Id.Equals(default(IdT)));
}
}