Free NHibernate BinaryBlobType

Today I am working on a MySQL database and I do not know how to match byte [] in the BLOB column ...

My table is as follows:

CREATE TABLE `images` ( `Id` INT NOT NULL AUTO_INCREMENT , `imgText` VARCHAR(45) NULL , `image` BLOB NULL , PRIMARY KEY (`Id`) ); 

Mapping:

 public class imagesMap : ClassMap<images> { public imagesMap() { Id(x => x.Id); Map(x => x.imgText); Map(x => x.image).CustomType<BinaryBlobType>(); } } 

Buisnessobject:

 public class images { public virtual int Id{get;set;} public virtual string imgText{get;set;} public virtual Byte[] image{get;set;} } 

If I run the application, I instantly got an exception:

NHibernate.MappingException: Failed to instantiate IType BinaryBlobType: System.MissingMethodException It says that for this IType is "No Constructor defined"

I can’t understand why it doesn’t work, everyone told me that I need to display CustomType ()

I would be grateful for every help!

Greetz, Benni

+4
source share
1 answer

Well, after 10 minutes, I myself found a solution to my problem.

For anyone who is also facing this problem:

To match

 public virtual byte[] array; 

In BLOB you do not need to define your own type, FNH does this even “automatically”.

The mapping for the byte array should work like this:

 Map(x=>x.array); 
+5
source

Source: https://habr.com/ru/post/1336299/


All Articles