2

SchemaExportデータベースとSQLスクリプトを生成するために使用する簡単なツールを作成します。単純なエンティティでは、1 つの文字列プロパティがSQL ServerDescriptionの列であると予想されますが、実際にはです。ntextnvarchar(255)

ここに画像の説明を入力

どの部分が間違っていたのかわかりません。アドバイスをいただければ幸いです。

以下は私のコードです。コンソールアプリを作成し、NHibernate実行するナゲットパッケージを追加するだけです。

using System;
using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.Driver;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Tool.hbm2ddl;

namespace ConsoleApplication1
{
public class Item
{
    public int Id { get; set; }
    public string Description { get; set; }
}

public class ItemMap : ClassMapping<Item>
{
    public ItemMap()
    {
        Id(e => e.Id, m => m.Generator(Generators.Identity));

        Property(e => e.Description, m =>
        {
            m.NotNullable(true);
            m.Length(int.MaxValue);
        });
    }
}

class Program
{
    private const string ConnectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=db01;Integrated Security=True";

    static void Main(string[] args)
    {
        var modelMapper = BuildModelMapper();
        var configuration = GetConfiguration();
        configuration.AddDeserializedMapping(modelMapper.CompileMappingForAllExplicitlyAddedEntities(), null);

        try
        {
            new SchemaExport(configuration).Execute(false, true, false);
            Console.WriteLine("Done");
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
        Console.ReadLine();
    }

    private static ModelMapper BuildModelMapper()
    {
        var mm = new ModelMapper();
        mm.AddMapping(typeof(ItemMap));
        return mm;
    }

    private static Configuration GetConfiguration()
    {
        var cfg = new Configuration();

        cfg.DataBaseIntegration(db =>
        {
            db.Driver<SqlClientDriver>();
            db.Dialect<MsSql2008Dialect>();
            db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
            db.ConnectionString = ConnectionString;
            db.LogFormattedSql = true;
            db.LogSqlInConsole = true;
            db.AutoCommentSql = true;
        });

        return cfg;
    }
}
}
4

1 に答える 1

3

さらに読んだ後、https://msdn.microsoft.com/en-us/library/ms187993.aspxntextとともに将来のバージョンで削除されますtext and image

ntext 、 text 、および image データ型は、Microsoft SQL Server の将来のバージョンで削除される予定です。新しい開発作業でこれらのデータ型を使用することは避け、現在それらを使用しているアプリケーションを変更することを計画してください。代わりに、nvarchar(max)、varchar(max)、および varbinary(max) を使用してください。

したがって、このコードは機能します

Property(e => e.Description, m =>
    {
        m.NotNullable(true);
        m.Length(4001); // any value > 4K
    });
于 2015-07-03T15:43:59.617 に答える