我希望得到答案,但我的答案是:不。我们必须将此值作为设置传递。原因是表格 hi-lo 生成器的实现方式。
检查TableHiLoGenerator 代码 .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)读取属性并将这些值传递给配置......这真的很极端,但可能是答案