2012-09-07 103 views
0

我需要驗證模式,我有一個對象與字節[]屬性(BLOB)。當我運行驗證時,我收到OverflowException:「Int32值過大或過小。」NHibernate:驗證模式與字節[]屬性

我使用NHibernate 3.1.0.400與FluentNHibernate 1.2.0.712 我已經創建了測試項目來檢查。下面是代碼(它屬於在驗證):

static void Main(string[] args) 
    { 
     var configuration = new NHibernate.Cfg.Configuration(); 

     string connectionString = "some connection string"; 
     Console.WriteLine("Running test with connection string: {0}", connectionString); 
     Dictionary<string, string> props = new Dictionary<string, string>() 
               { 
                {"connection.provider", "NHibernate.Connection.DriverConnectionProvider"}, 
                {"connection.driver_class", "NHibernate.Driver.MySqlDataDriver"}, 
                {"connection.connection_string", connectionString}, 
                {"dialect", "NHibernate.Dialect.MySQL5Dialect"}, 
               }; 
     configuration.AddProperties(props); 
     var mappings = Fluently.Configure(configuration) 
      .Mappings(m => m 
           .FluentMappings.AddFromAssemblyOf<DataResource>() 
           .Conventions.AddFromAssemblyOf<DataResource>()); 

     var sessionFactory = mappings 
       .ExposeConfiguration(DoExtendedConfiguration) 
       .BuildSessionFactory(); 
    } 

    private static void DoExtendedConfiguration(Configuration configuration) 
    { 
     SchemaExport schemaExport = new SchemaExport(configuration).SetDelimiter(";").SetOutputFile("schema.sql"); 
     schemaExport.Create(false, true); 

     SchemaValidator schemaValidator = new SchemaValidator(configuration); 
     schemaValidator.Validate(); 
    } 

public class DataResource 
{ 
    public int Id { get; set; } 
    public byte[] Value { get; set; } 
} 
public class DataResourceMap : ClassMap<DataResource> 
{ 
    public DataResourceMap() 
    { 
     Id(x => x.Id); 
     Map(x => x.Value); 
    } 
} 
+0

在MS SQL中可以正常工作,它會創建一個VARBINARY(8000)列。你可以嘗試明確地設置一個很大的值字段的長度,如http://stackoverflow.com/a/4723020/43846 – stuartd

+0

試過,沒有幫助我。 – Archeg

回答

0

我沒有找到有關官員,錯誤沒有提到,但我更新FluentNhibernate和NHibernate後,最後一個可用的版本(通過的NuGet),發行解決。這套房適合我,所以我會解決問題,好像沒人發現任何其他解決方案和堆棧允許我那樣做。