Fluent NHibernate BinaryBlobType
今天我正在开发 MySQL 数据库,我不知道如何将 Byte[] 映射到 BLOB 列...
我的表看起来是这样的:
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>();
}
}
Buisnessobject:
public class images {
public virtual int Id{get;set;}
public virtual string imgText{get;set;}
public virtual Byte[] image{get;set;}
}
如果我启动我的应用程序,我会立即收到异常:
NHibernate.MappingException:无法实例化 IType BinaryBlobType:System.MissingMethodException 他说这个 IType 是“没有定义构造函数”,
我无法理解为什么它不起作用,每个人都告诉我我只需要映射 CustomType()
我将不胜感激每一个帮助!
格雷兹,本尼
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,10 分钟后我自己找到了问题的解决方案。
对于同样遇到这个问题的每个人:
为了将 a 映射
到 BLOB,您不需要定义自定义类型,FNH 甚至“自动”执行此操作。
字节数组的映射应该这样工作:
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
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: