How to specify type of column in free state nHibernate?

I have a class CaptionItem

public class CaptionItem
    {
        public virtual int SystemId { get; set; }
        public virtual int Version { get; set; }        
        protected internal virtual IDictionary<string, string> CaptionValues {get; private set;}
}

I use the following code to display nHibernate

Id(x => x.SystemId);
            Version(x => x.Version);
            Cache.ReadWrite().IncludeAll();
            HasMany(x => x.CaptionValues)
                .KeyColumn("CaptionItem_Id")
                .AsMap<string>(idx => idx.Column("CaptionSet_Name"), elem => elem.Column("Text"))
                .Not.LazyLoad()
                .Cascade.Delete()
                .Table("CaptionValue")
                .Cache.ReadWrite().IncludeAll();

So, two tables are created in the database. One CaptionValueand the others CaptionItem. There CaptionItemare three columns in the table .

1. CaptionItem_Id     int
2. Text               nvarchar(255)
3. CaptionSet_Name    nvarchar(255)

Now, my question is: how can I make the column type Textup nvarchar(max)?

Thanks in advance.

+3
source share
2 answers

I tried a lot of things, but nothing solved the problem. In the end, I decided this. I changed the conversion code a bit. The new display code is shown below.

Id(x => x.SystemId);
            Version(x => x.Version);
            Cache.ReadWrite().IncludeAll();
            HasMany(x => x.CaptionValues)
                .KeyColumn("CaptionItem_Id")
                .AsMap<string>(idx => idx.Column("CaptionSet_Name"), elem => elem.Columns.Add("Text", c => c.Length(10000)))
                .Not.LazyLoad()
                .Cascade.Delete()
                .Table("CaptionValue")
                .Cache.ReadWrite().IncludeAll();

So, I just added c => c.Length(10000). Now the column type Textwill be in the database nvarchar(MAX).

, - .

+2

, :

Id(x => x.Text).CustomSqlType("nvarchar(max)"); 

// For older versions of Fluent NHibernate   
Id(x => x.Text).CustomSqlTypeIs("nvarchar(max)"); 

Edit:

Bipul, CaptionValues , , Text - nvarchar (max)?

+1

Source: https://habr.com/ru/post/1741265/


All Articles