1

私は (nuget から) MySql に OrmLite を使用しており、コンテンツがシリアル化されて blob される結果になるいくつかのオブジェクトを永続化しています。私が見つけたのは、これらのフィールドのスキーマがデフォルトで varchar(255) になっていることです。これは小さなブロブでのみ機能します。比較的小さなリストでも、255 文字には大きすぎます。

OrmLite を使用するときに、ブロブ テーブルのサイズを正しく設定するには、どのような方法が最適ですか?

例:

public class Foo : IHasId<long>
{
  [AutoIncrement]
  public long Id { get; set; }

  public Dictionary<string, string> TestSize { get; set; }
}

私が今取っているアプローチは[StringLength(6000)]、ブロブ化されたフィールドごとに注釈を付けることです。これは機能しますが、十分なスペースを確保するためのより良い方法があるかどうかはわかりません。

以下は、サイジングの問題を示す完全な単体テストです。

using NUnit.Framework;
using ServiceStack.DataAnnotations;
using ServiceStack.DesignPatterns.Model;
using ServiceStack.OrmLite;
using ServiceStack.OrmLite.MySql;
using System;
using System.Collections.Generic;
using System.Configuration;

namespace OrmLiteTestNamespace
{
    [TestFixture]
    public class BlobItemTest
    {
        [Test]
        public void TableFieldSizeTest()
        {
            var dbFactory = new OrmLiteConnectionFactory(
                  ConfigurationManager.AppSettings["mysqlTestConn"],
                  MySqlDialectProvider.Instance);
            using (var db = dbFactory.OpenDbConnection())
            {
                db.CreateTableIfNotExists<Foo>();
                var foo1 = new Foo()
                    {
                        TestSize = new Dictionary<string, string>()
                    };

                // fill the dictionary with 300 things
                for (var i = 0; i < 300; i++)
                {
                    foo1.TestSize.Add(i.ToString(), Guid.NewGuid().ToString());
                }
                // throws MySql exception "Data too long for column 'TestSize' at row 1"
                db.Insert(foo1);

            }
        }

    }
    public class Foo : IHasId<long>
    {
        [AutoIncrement]
        public long Id { get; set; }

        public Dictionary<string, string> TestSize { get; set; }
    } 
}
4

1 に答える 1