使用Fluent NHibernate映射大字符串

时间:2010-06-23 20:42:52

标签: c# .net nhibernate fluent-nhibernate nhibernate-mapping

我正在使用Oracle DB,我正在尝试映射此类:

public class Book
{
    public virtual int Id { get; private set; }
    public virtual string Author { get; set; }
    public virtual string Title { get; set; }
    public virtual string Text { get; set; }
}

使用此映射类:

public class BookMap : ClassMap<Book>
{
    public BookMap()
    {
        Id(x => x.Id);
        Map(x => x.Author);
        Map(x => x.Title);
        Map(x => x.Text);
    }
}

但它生成的列类型是NVARCHAR(255),而Book.Text属性的字符数远远超过255个。

如何将其映射到可以包含非常大的字符串的类型(例如CLOB)?

1 个答案:

答案 0 :(得分:9)

public class BookMap : ClassMap<Book>
{
    public BookMap()
    {
        Id(x => x.Id);
        Map(x => x.Author);
        Map(x => x.Title);
        Map(x => x.Text).CustomSqlType("CLOB");
    }
}

public class BookMap : ClassMap<Book>
{
    public BookMap()
    {
        Id(x => x.Id);
        Map(x => x.Author);
        Map(x => x.Title);
        Map(x => x.Text).Length(500);  // nvarchar(500)
    }
}