Mapping large string with Fluent NHibernate

痞子三分冷 提交于 2019-12-23 09:27:54

问题


I'm working with an Oracle DB, and I'm trying to map this class:

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; }
}

With this mapping class:

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

But the column type that it generates me is NVARCHAR(255), And the Book.Text Property has much more than 255 characters.

How can I map it to a type that can contain a very large string (for example CLOB)?


回答1:


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");
    }
}

or

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)
    }
}


来源:https://stackoverflow.com/questions/3105391/mapping-large-string-with-fluent-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!