值对象列表的 Fluent NHibernate 约定是什么

发布于 2024-08-14 07:22:43 字数 911 浏览 1 评论 0原文

我试图弄清楚值对象列表(在本例中为 IList)的约定是什么。这里是我的域模型的代码片段:

public class RegionSetting : Entity {
    public virtual bool Required { get; set; }
    public virtual string Name { get; set; }
    public virtual IList<string> Options { get; set; }
}

我的自动映射设置为:

public class RegionSettingMap : IAutoMappingOverride<RegionSetting> {
    public void Override(AutoMapping<RegionSetting> mapping) {
        mapping
            .HasMany(x => x.Options).Element("Options")
            .Table("RegionSettingOptions")
            .KeyColumn("RegionSettingId");
    }
}

我想将 .Table().KeyColumn() 重写为约定,以便我不必在使用 IList 的所有地方都这样做。我认为我可以创建一个 IHasManyConvention,但它似乎不会影响此映射。我在自定义 HasManyConvention 类中设置了一个断点,但它不会因 Options 属性而中断。谁能告诉我应该使用什么约定来自动执行此覆盖?

I'm trying to figure out what the convention would be for a value object list, in this case an IList. Here a code fragment for my domain model:

public class RegionSetting : Entity {
    public virtual bool Required { get; set; }
    public virtual string Name { get; set; }
    public virtual IList<string> Options { get; set; }
}

My automapping is set to:

public class RegionSettingMap : IAutoMappingOverride<RegionSetting> {
    public void Override(AutoMapping<RegionSetting> mapping) {
        mapping
            .HasMany(x => x.Options).Element("Options")
            .Table("RegionSettingOptions")
            .KeyColumn("RegionSettingId");
    }
}

I'd like to make the .Table() and .KeyColumn() overrides into a convention so that I don't have to do that everywhere I'm using IList<string>. I thought that I could create an IHasManyConvention, but it doesn't seem to affect this mapping. I set a breakpoint in my custom HasManyConvention class, but it doesn't break for the Options property. Could anyone tell me what convention I should be using to automate this override?

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

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

发布评论

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

评论(1

深爱不及久伴 2024-08-21 07:22:43

使用 IHasManyConvention 应该可以工作。尝试使用 IBagConvention,看看是否有效。如果没有,那就是里面有 bug。

Using an IHasManyConvention should've worked. Try an IBagConvention, see if that works. If not, there's a bug in there.

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