开发者

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

开发者 https://www.devze.com 2023-01-24 17:29 出处:网络
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

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, h开发者_如何转开发ow would you do this with a convention or mapping overrides?

Thx!


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号