Nels_P_Olsen wrote:
I can try that. BTW, is that what the AnsiString (or AnsiStringFixedLength) type is for? It isn't documented as to how it is different from the String type, and since it doesn't trim values, we considered it worthless and didn't look into any further ...
AnsiStringFixedLength is used to map a database column of type CHAR (in Sql Server at least), AnsiString is used to map to VARCHAR, String is used to map to NVARCHAR and StringFixedLength is used to map to NCHAR. I don't believe NHibernate changes too much in how these are handled besides using ansi types or unicode types when talking with the database. I believe the main point in using these types is to allow NHibernate to generate the database schema, I may be wrong about that.
I don't believe NHibernate handles the 4 types much differently in the NHibernate types.
Nels_P_Olsen wrote:
Since we only use field-based mapping, we can also have our Id properties always trim the field before returning it in the getter, and always pad the value before assigning it to the field in the setter. At least that way it will always appear trimmed to us, and always padded to NHibernate.
That works, but if that is too ugly you could also try another approach. I don't know if you would find this more offensive or not. You could also create an interface which defines the identifier of the class. Then implement the interface explicitly on the class. You can have NHibernate access the property using the explicit interface but your developers won't see that reserved property unless they explicitly cast your object as the interface. To prevent that from happening I'll mark the property on the interface as obsolete, which would stop it at compile time (provided they weren't also using reflection).
It's really up to you if that approach is uglier or not. I think all of the 3 options should work. I may be wrong though.