自动映射继承:如何为基类添加鉴别器约定

发布于 2024-08-22 06:02:13 字数 181 浏览 5 评论 0原文

通过实现 ISubclassConvention,我可以更改类层次结构中子类的鉴别器值。我现在正在寻找一种方法来为我的基类设置鉴别器值。有没有办法通过约定覆盖来更改它,或者我是否必须为我的层次结构添加手动映射?

(IClassConvention 提供了 DiscriminatorValue 属性,但它是只读的,所以运气不佳。)

By implementing ISubclassConvention, I can change the Discriminator Value for the subclasses in my class hierarchy. I'm now looking for a way to set the Discriminator Value for my base classes as well. Is there a way to change it with a convention override or do I have to add a manual mapping for my hierarchy?

(The IClassConvention provides the DiscriminatorValue property but it is read-only, so no luck there.)

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

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

发布评论

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

评论(1

世界和平 2024-08-29 06:02:13

我知道的唯一方法是为基类进行简单的映射覆盖。

public class DepotMappingOverride : IAutoMappingOverride<Depot>
{
    /// <summary>
    /// Alter the auto mapping for this type
    /// </summary>
    /// <param name="mapping">Auto mapping</param>
    public void Override(AutoMapping<Depot> mapping)
    {
        mapping.DiscriminateSubClassesOnColumn("Type", "BaseDepot");
    }
}

现在“BaseDepot”将是 Depot 类的鉴别器值。

The only way I know is to make simple mapping override just for base class.

public class DepotMappingOverride : IAutoMappingOverride<Depot>
{
    /// <summary>
    /// Alter the auto mapping for this type
    /// </summary>
    /// <param name="mapping">Auto mapping</param>
    public void Override(AutoMapping<Depot> mapping)
    {
        mapping.DiscriminateSubClassesOnColumn("Type", "BaseDepot");
    }
}

Now "BaseDepot" will be discriminator value for Depot class.

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