FluentNHibernate HiLo - 可以从 table 读取 maxLo 而不是在代码中硬连线吗?

FluentNHibernate HiLo - can be maxLo read from table and not to be hardwired in code?

我正在使用

GeneratedBy.HiLo(string table, string column, string maxLo, string where);

为主键。目前我正在寻找如何从 table 加载 maxLo 而不是将其作为常量存储在代码中的可能性。 NextHi 的值是从数据库 table 加载的(好的,它必须是否则整个概念将根本无法工作)。但是我也没有找到如何从 table 加载 maxLo 的方法。从快速代码研究来看,这似乎是不可能的,但也许我仍然遗漏了一些东西。

我需要它的原因:我有业务应用程序和单独的配置应用程序,如果它向 tables 中插入某些内容,则需要使用相同的 maxLo 来保持 id 的一致性。当然应用可以是运行独占。 两种可能的解决方法: - 我可以有一些共享的 Dll,其中将存储 maxLo - 我可以在数据库中使用 table 并自行加载 maxLo

但如果没有任何变通办法,按照我的意愿去做还是可以的。

FluentNHibernate 版本:2.0.1.0

我希望得到 的答案,但我的答案是:没有。我们必须将此值作为设置传递。原因在于 table hi-lo 生成器的实现方式。

勾选TableHiLoGenerator code .Configure()

/// <summary>
/// Configures the TableHiLoGenerator by reading the value of <c>table</c>, 
/// <c>column</c>, <c>max_lo</c>, and <c>schema</c> from the <c>parms</c> parameter.
/// </summary>
/// <param name="type">The <see cref="IType"/> the identifier should be.</param>
/// <param name="parms">An <see cref="IDictionary"/> of Param values that are keyed by parameter name.</param>
/// <param name="dialect">The <see cref="Dialect.Dialect"/> to help with Configuration.</param>
public override void Configure(IType type, IDictionary<string, string> parms, Dialect.Dialect dialect)
{
    base.Configure(type, parms, dialect);
    maxLo = PropertiesHelper.GetInt64(MaxLo, parms, Int16.MaxValue);
    lo = maxLo + 1; // so we "clock over" on the first invocation
    returnClass = type.ReturnedClass;
}

最有趣的部分是评论:

//Configures the TableHiLoGenerator by reading the value of <c>table</c>, 
// <c>column</c>, <c>max_lo</c>, and <c>schema</c> from the <c>parms</c> parameter.

和参数IDictionary<string, string> parms

在极端情况下,我们可以使用此 (及其流畅版本:GeneratedBy.HiLo(...) - 从中​​读取属性在某处 (例如 ADO.NET) 并将这些值传递给配置...这确实很极端,但可能是 the 答案