我正在使用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)?
答案 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)
}
}