Fluent NHibernate: How do you change the underlying sql type for an automapped collection of strings?

796 Views Asked by At

I have a class:

public class ParentClass
{
     //other stuff
     IList<string> ChildPages
}

When 'IList<string> ChildPages' gets automapped by Fluent NHibernate a 'ChildPages' join table is created with a nvarchar(255) backing field for each string in the collection.

But the problem is that I want the sql backing field to be 'text', so that I can have lengthy entries for this entity.

What's the easiest way to make this change?

How do you change the underlying type of automapped primitive collections?

Also, for extra points, how would you do this with a convention or mapping overrides?

Thx!

1

There are 1 best solutions below

1
On

You can setup an override convention so that strings use text instead of nvarchar2 (255), as shown in the solution on this other thread. If you only want such behavior for a specific property, something like this in your fluent configuration would work:

AutoMap
    .AssemblyOf<ParentClass>()
    .Override<ChildPage>(map =>
        {
            mapping.Map(x => x.Page).CustomType("StringClob").CustomSqlType("text");
        });