[NH Mapping Attributes] AttributeIdentifier doesn't work for param

Skip to first unread message

Michael Kotten

Dec 24, 2010, 3:31:28 AM12/24/10
to NHibernate Contrib - Development Group

I've been using NH Mappng Attributes for a long time now with great
success. I always liked the ability to use the AttributeIdentifier to
define values for placeholders. But there's a missing part where the
AttributeIdentifier isn't taken into account.
I was trying to create a base class similar to the example in
http://www.nhforge.org/doc/nh/en/index.html#mapping-attributes. It
uses a property for the identifier. But in my scenario i'm using a
sequence generator, so i tried to create this mapping:

public class Base {
[Id(0, Name = "Id", Column = "{{Id.Column}}", UnsavedValue = "0",
TypeType = typeof(long))]
[Generator(1, Class = "sequence")]
[Param(2, Name = "sequence", Content = "{{Id.Sequence}}")]
[AttributeIdentifier("Id.Column", Value = "ID")]
[AttributeIdentifier("Id.Sequence", Value = "sq_id")]
public long Id { ... }

The content of the param attribute doesn't get replaced by the defined
value ("sq_id") when creating the mapping.
I fixed this myself by subclassing HbmWriter and overriding
WriteParam(...) like this:

public override void WriteParam(System.Xml.XmlWriter writer,
System.Reflection.MemberInfo member, ParamAttribute attribute,
BaseAttribute parentAttribute, System.Type mappedClass) {
// Attribute: <name>
writer.WriteAttributeString("name", attribute.Name == null ?
DefaultHelper.Get_Param_Name_DefaultValue(member) :
GetAttributeValue(attribute.Name, mappedClass));

WriteUserDefinedContent(writer, member, null, attribute);

// Write the content of this element (mixed="true")
// PATCH: Using GetAttributeValue to ensure that
AttributeIdentifier is considered.


I don't see any reason why the param attribute shouldn't be taken into
account, so it would be great if you could include my little patch in
your project, so i can remove my patched version.
Reply all
Reply to author
0 new messages