NHibernate 按代码映射 (Loquacious) - 级联选项 [英] NHibernate mapping by code (Loquacious) - Cascade options

查看:20
本文介绍了NHibernate 按代码映射 (Loquacious) - 级联选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用 NHibernate Mapping By Code 时的 Cascade 枚举选项行为有疑问.

I have a question on Cascade enum options behavior when using NHibernate Mapping By Code.

Enum 有以下选项:

Enum has following options:

[Flags]
public enum Cascade
{
    None = 0,
    Persist = 2,
    Refresh = 4,
    Merge = 8,
    Remove = 16,
    Detach = 32,
    ReAttach = 64,
    DeleteOrphans = 128,
    All = 256,
}

它们旨在用作位标志组合(据我所知).

They are intended to be used like bit flag combinations (as far as I get it).

我查看了 NHibernate 文档,其中定义了以下 XML 映射的级联选项:生命周期和对象图

I've looked thru NHibernate documentation, and the following cascade options for XML mappings are defined there: Lifecycles and object graphs

任何人都可以通过代码描述来自新 Nhibernate 映射的级联选项吗?其中一半是自我描述,另一半不是.

Can anyone describe cascade options from new Nhibernate mapping by code? Half of them are self describing, other half is not.

推荐答案

From srcNHibernateMappingByCodeImplCascadeConverter.cs

    private static IEnumerable<string> CascadeDefinitions(this Cascade source)
    {
        if (source.Has(Cascade.All))
        {
            yield return "all";
        }
        if (source.Has(Cascade.Persist))
        {
            yield return "save-update, persist";
        }
        if (source.Has(Cascade.Refresh))
        {
            yield return "refresh";
        }
        if (source.Has(Cascade.Merge))
        {
            yield return "merge";
        }
        if (source.Has(Cascade.Remove))
        {
            yield return "delete";
        }
        if (source.Has(Cascade.Detach))
        {
            yield return "evict";
        }
        if (source.Has(Cascade.ReAttach))
        {
            yield return "lock";
        }
        if (source.Has(Cascade.DeleteOrphans))
        {
            yield return "delete-orphan";
        }
    }

注意:all 级联除delete-orphan 之外的所有.

Note: all cascades all except of delete-orphan.

这篇关于NHibernate 按代码映射 (Loquacious) - 级联选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆