Hi,

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) {
      writer.WriteStartElement("param");
      // 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.
      writer.WriteString(GetAttributeValue(attribute.Content,
mappedClass));

      writer.WriteEndElement();
    }

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.

-- 
You received this message because you are subscribed to the Google Groups 
"NHibernate Contrib - Development Group" 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/nhcdevs?hl=en.

Reply via email to