How to map Image type in NHibernate?

I have at my SQL Server 2000 Database a column with type Image. How can I map it into NHibernate?

  • How to use SQL Server stored procedures in Microsoft PowerBI?
  • Add visual fox pro database as a linked server in Microsoft SQL
  • SQL server not returning all rows
  • Async behavior in C# IIS and SQL Server
  • Can JDBC client execute SET ARITHABORT ON on Microsoft SQL Server 2012?
  • XML Query within SQL Server
  • SQL Retrieve historical sensor values at specific date times
  • Override default entity property names
  • Click Button on ListView is not working
  • Insert values into multiple SQL tables
  • How to change previous and next 7 days using bar charts mvc c#?
  • Select All checkboxes button in DetailsView errors
  • 3 Solutions collect form web for “How to map Image type in NHibernate?”

    We used BinaryBlob on the mapping config file, and byte[] on the property.

    Below is the sample code that i have used to map an image field. Where BlogImage was a column of Image Datatype mapped to byte type property BlogImage. length=”2147483647″ was used to ensure copy of full image in to database as nhibernate some times limit the max size of data that is going to be inserted.

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
    <class name="EAS.MINDSPACE.Infrastructure.Business.Entities.BlogMaster,EAS.MINDSPACE.Infrastructure.Business.Entities" lazy="false" table="BlogMaster" schema="dbo" >
    <id name="BlogId" column="BlogId">
      <generator class="native" />
    </id>
    <property name="BlogData" column="BlogData" />
    <property name="BlogImage" column="BlogImage" length="2147483647"  />
    <property name="UserId" column="UserId" />
      <property name="CreatedByName" column="CreatedBy" />
      <property name="CreatedOn" column="CreatedOn" />
      <property name="ReplyCount" column="ReplyCount" />
    
     </class>
    </hibernate-mapping>
    

    NHibernate 3.x does all the magic it self.

    Sql:

    Create table tblCompany (..., Logo image);
    

    NHibernate-Mapping (important to set length!!!):

    <class name="Company"
         table="tblCompany">
         ...         
         <property name="_logo"
              column="Logo"
              not-null="false"
              length="2147483647"
              access="field" />
         ...
    </class>
    

    C#-Class:

    public class Company {
        ...
        private Image _logo;
        ...
    }
    
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.