Fluent NHibernate BinaryBlobType

我们两清 提交于 2019-12-23 15:18:59

问题


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


回答1:


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);


来源:https://stackoverflow.com/questions/4746142/fluent-nhibernate-binaryblobtype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!