首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NHibernate SchemaExport不创建ntext列。

NHibernate SchemaExport不创建ntext列。
EN

Stack Overflow用户
提问于 2015-07-03 15:07:55
回答 1查看 221关注 0票数 2

我创建了一个简单的工具,它使用SchemaExport生成数据库& sql脚本。在一个简单的实体上,一个字符串属性Description是Server中的一个ntext列,但实际上它是nvarchar(255)

不确定哪一部分我错了,任何建议都是感激的!

下面是我的代码,只需创建一个控制台应用程序+添加NHibernate nuget包运行。

代码语言:javascript
复制
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;
    }
}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-03 15:43:59

经过进一步阅读,ntext将与text and image https://msdn.microsoft.com/en-us/library/ms187993.aspx一起在未来版本中被删除。

ntext、文本和图像数据类型将在的未来版本中删除。避免在新的开发工作中使用这些数据类型,并计划修改当前使用它们的应用程序。使用nvarchar(max)、varchar(max)和var二进制(Max)代替。

所以这段代码会起作用

代码语言:javascript
复制
Property(e => e.Description, m =>
    {
        m.NotNullable(true);
        m.Length(4001); // any value > 4K
    });
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31209851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档