【问题标题】:NHibernate: validate schema with byte[] propertyNHibernate:使用 byte[] 属性验证模式
【发布时间】:2012-09-07 12:51:27
【问题描述】:

我需要验证架构,其中我有一个具有 byte[] 属性 (BLOB) 的对象。当我运行验证时,我收到 OverflowException:“对于 Int32,值太大或太小。”

我正在使用 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);
    }
}

【问题讨论】:

  • 在 MS SQL 中工作正常,它创建了一个 VARBINARY(8000) 列。您可以尝试像stackoverflow.com/a/4723020/43846 那样为值字段显式设置较大的长度

标签: c# mysql nhibernate fluent-nhibernate


【解决方案1】:

我没有在官方上找到任何关于此类错误的提及,但是在我将 FluentNhibernate 和 Nhibernate 更新到最后一个可用版本(通过 Nuget)后,问题解决了。这很适合我,所以我将结束这个问题,好像没有人找到任何其他解决方案并且堆栈允许我这样做。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    • 1970-01-01
    • 1970-01-01
    • 2014-03-16
    • 1970-01-01
    相关资源
    最近更新 更多