2010-06-23 189 views
6

我與Oracle數據庫的工作,和我想這個類映射:映射大串功能NHibernate

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

看到http://stackoverflow.com/questions/2343105/override-for-fluent-nhibernate-for-long-text-strings-nvarcharmax-not-nvarchar – 2012-10-30 14:20:50

回答

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

待辦事項你的意思是'CustomType(「StringClob」)'? – 2012-10-30 13:24:20

+0

@ChrisS。 StringClob用於SQL Server,問題是關於Oracle – 2012-10-31 12:07:52

+0

StringClob在SQL Server 2008上不起作用。 – 2012-12-07 03:12:08