Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 702
Victor Rodrigues Avatar asked Dec 03 '08 16:12

Victor Rodrigues


2 Answers

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

like image 87
Victor Rodrigues Avatar answered Nov 13 '22 13:11

Victor Rodrigues


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>
like image 20
Abhijit_Srikumar Avatar answered Nov 13 '22 14:11

Abhijit_Srikumar