如何在NHibernate中映射图像类型?

时间:2021-10-14 11:23:27

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

我在我的SQL Server 2000数据库中有一个类型为Image的列。我怎样才能将它映射到NHibernate?

3 个解决方案

#1


13  

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

我们在映射配置文件上使用了BinaryBlob,在属性上使用了byte []。

#2


1  

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.

下面是我用于映射图像字段的示例代码。其中BlogImage是映射到字节类型属性BlogImage的Image Datatype列。 length =“2147483647”用于确保将完整映像复制到数据库中,因为nhibernate有时会限制要插入的数据的最大大小。

<?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>

#3


0  

NHibernate 3.x does all the magic it self.

NHibernate 3.x完成了它自己的所有魔力。

Sql:

SQL:

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

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

NHibernate-Mapping(设置长度!!!):

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

C#-Class:

C#-Class:

public class Company {
    ...
    private Image _logo;
    ...
}

#1


13  

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

我们在映射配置文件上使用了BinaryBlob,在属性上使用了byte []。

#2


1  

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.

下面是我用于映射图像字段的示例代码。其中BlogImage是映射到字节类型属性BlogImage的Image Datatype列。 length =“2147483647”用于确保将完整映像复制到数据库中,因为nhibernate有时会限制要插入的数据的最大大小。

<?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>

#3


0  

NHibernate 3.x does all the magic it self.

NHibernate 3.x完成了它自己的所有魔力。

Sql:

SQL:

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

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

NHibernate-Mapping(设置长度!!!):

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

C#-Class:

C#-Class:

public class Company {
    ...
    private Image _logo;
    ...
}