连贯的NHibernate BinaryBlobType [英] Fluent NHibernate BinaryBlobType
问题描述
我的表这样看来:
CREATE TABLE`images`(
`Id` INT NOT NULL AUTO_INCREMENT,
`imgText` VARCHAR(45)NULL,
`image` BLOB NULL,
PRIMARY KEY(`Id`));
映射:
public class imagesMap:ClassMap< images> {
public imagesMap(){
Id(x => x.Id);
Map(x => x.imgText);
Map(x => x.image).CustomType< BinaryBlobType>();
$ b Buisnessobject:
public class images {
public virtual int Id {get; set;}
public virtual string imgText {get; set; }
public virtual Byte [] image {get; set;}
}
如果我开始我的应用程序,我立即得到一个例外:
NHibernate.MappingException:无法实例化类型BinaryBlobType:System.MissingMethodException
他说这个IType是没有构造函数定义
我不能unterstand为什么它不工作,大家告诉我,我只需要映射CustomType()
我很感激每一个帮助!
Greetz,Benni
解决方案10分钟后,我自己找到了解决问题的办法。
对于那些也陷入这个问题的人们来说:
>
映射a
公共虚拟字节[]阵列;
对于BLOB,您不需要定义自定义类型,FNH甚至可以自动
字节数组的映射应该是这样的:
$ p $ 地图(X => x.array);
today i'm working on a MySQL Database, and i don't know how to Map a Byte[] to a BLOB Column...
My Table looks this way:
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 Start my Application i got instantly a Exception:
NHibernate.MappingException: Could not instantiate IType BinaryBlobType: System.MissingMethodException
He says for this IType is "No Constructor defined"
I can't unterstand why it is not working, everybody told me i only has to map the CustomType()
I would appreciate each help!
Greetz, Benni
解决方案 Ok, 10 Minutes later i found the Solution for my Problem by myself.
For everybody who also get stuck with this Problem:
For Mapping a
public virtual byte[] array;
To a BLOB you don't need to Define a custom Type, FNH does even this "automagically".
The Mapping for the Byte-Array should work so:
Map(x=>x.array);
这篇关于连贯的NHibernate BinaryBlobType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文