在Informix数据库和FluentNhibernate中保存Smart Blob

时间:2015-06-02 15:46:35

标签: c# fluent-nhibernate blob informix

我需要在informix数据库中保存一个Smart Blob,这是我的模型:

 public class ArtistaFoto : Entity
{
    public virtual Artista Artista { get; set; }
    public virtual int NumeroSeq { get; set; }
    public virtual byte[] BlobArtistas { get; set; }
    public virtual string NomeArquivos { get; set; }
    public virtual string Extensao { get; set; }
}

有我的地图

       public ArtistaFotosMapping()
    {
        this.Table("sb_aneartistas");
        this.CompositeId().KeyReference(x => x.Artista, "cdartista").KeyProperty(x => x.NumeroSeq, "nrseq");
        this.Map(x => x.BlobArtistas).Column("sbaneartistas");
        this.Map(x => x.NomeArquivos).Column("nome_arq");
        this.Map(x => x.Extensao).Column("extensao");
    }

当我尝试保存我的实体时有例外

enter image description here

所以我知道Informix数据库中的这个字段是一个SmartBlob,这不是普通的blob(字节或字符串)。有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

我的困难在于建立连接:

   ISessionFactory factory = Fluently.Configure()
                          .Database(
                IfxSQLIConfiguration
               .Informix1000
              .ConnectionString("Provider=Ifxoledbc.2;Password=xxxx;Persist Security Info=True;User ID=xxxx;Data Source=xxxx")
                             .Driver<OleDbDriver>()
               .Dialect<InformixDialect1000>()
               .ShowSql())
               .Mappings(x => x.FluentMappings.AddFromAssemblyOf<ArtistaFotoMapping>()
               ).ExposeConfiguration(x =>
                  x.SetProperty(NHibernate.Cfg.Environment.PrepareSql, "True")
               )
               .BuildSessionFactory();` 

我更改了示例后面的IfxOdbcConfiguration:

  ISessionFactory factory = Fluently.Configure()
  .Database(
    IfxOdbcConfiguration
    .Informix1000
    .ConnectionString("DRIVER={IBM INFORMIX ODBC DRIVER};SERVER=xxxx;DATABASE=xxxx;UID=xxx;PWD=xxx;NEEDODBCTYPESONLY=1;")
    .ShowSql())
    .Mappings(x => x.FluentMappings.AddFromAssemblyOf<ArtistaFotoMapping>()
    ).ExposeConfiguration(x =>
       x.SetProperty(NHibernate.Cfg.Environment.PrepareSql, "False")
    )
    .BuildSessionFactory();