Fluent NHibernate:如何更改自动映射字符串集合的底层 sql 类型?

发布于 2024-10-01 20:48:57 字数 500 浏览 0 评论 0原文

我有一堂课:

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

当 'IList; ChildPages' 通过 Fluent NHibernate 自动映射,使用 nvarchar(255)< 创建“ChildPages”连接表/code> 集合中每个字符串的支持字段。

但问题是我希望 sql 支持字段为“text”,这样我就可以为该实体提供冗长的条目。

进行此更改的最简单方法是什么?

如何更改自动映射的原始集合的基础类型?

另外,为了额外的好处,您将如何通过约定或映射覆盖来做到这一点?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

总攻大人 2024-10-08 20:48:57

您可以设置覆盖约定,以便字符串使用 text 而不是 nvarchar2 (255),如解决方案 在另一个线程上。如果您只希望特定属性有这样的行为,那么在您的流畅配置中类似这样的东西就可以工作:

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

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");
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文