views:

155

answers:

1

I'm building an ASP.NET web application using NHibernate and a legacy database. In that database are fields of HTML stored as VARBINARY(MAX). The existing queries cast that data using CONVERT(VARCHAR(MAX), mainText). How can I do the same using NHibernate's HBM mapping?

A: 

Well, if all else fails remember your class can support this.

Psuedo Code:

public class MyPOCO {
 public virtual byte[] myHTMLByteArray { get; set; }
 public string myHTML {
  get {
   if(myHTMLByteArray != null) {
     return Encoding.ASCII.GetString(myHTMLByteArray);
    }
    return null;
  }
  set {
    myHTMLByteArray = Encoding.ASCII.GetBytes(value);
  }
}
Wayne
Very good point. I'm an NHibernate noob so I wasn't sure if I would do that or let some setting in the mapping handle it.
Mattio
Don't forget to mark this as an answer if you get no other responses
Wayne