设定:
流利配置:
var configuration = Fluently.Configure()
.Database(OracleManageDataClientConfiguration.Oracle10
.ConnectionString("my-connection-string")
.IsolationLevel(IsolationLevel.ReadCommitted).ShowSql())
.Mappings(x => x.FluentMappings.AddFromAssembly(my-assembly)
.Convention.Add<CustomIdentityHiloConvetion>())
.ExposeConfiguration(buildSchema)
.BuildConfiguration();
流利公约:
public class CustomIdentityHiloConvetion : IIdConvention
{
public void Apply(IIdentityInstance instance)
{
instance.GeneratedBy.HiLo("NEXTHIVALUETABLE", "NEXTHIVALUECOLUMN", 10, builder =>
builder.AddParam("where", string.Format("{0} = '{1}'", "TABLENAME", instance.EntityType.Name.ToUpperInvariant())));
}
}
来自Nhibernate的生成的SQL语句: 从NEXTHIVALUETABLE中选择NEXTHIVALUECOLUMN,其中TABLENAME ='MYSAMPLETABLE'用于更新
它抛出错误,它无法使用该语句从表NEXTHIVALUETABLE读取hi值。我直接在Toad中执行上述语句并运行完美且SQLite表。
我使用来自Nhibernate.Id命名空间的TableGenerator类(第193行)中的command.ExecuteReader语句反汇编(使用resharper)Nhibernate程序集返回no记录,因此它抛出此异常。
DoWorkInCurrentTransaction方法的快速代码:
do
{
IDbCommand command = conn.CreateCommand();
IDataReader rs = (IDataReader) null;
command.CommandText = this.query; // select NEXTHIVALUECOLUMN from NEXTHIVALUETABLE where TABLENAME = 'MYSAMPLETABLE' for update
command.CommandType = CommandType.Text;
command.Transaction - transaction;
PersistentIdGeneratorParmsNames.SqlStatementLogger.LogCommand("Reading high value: ", command, FormatStyle.Basic);
try
{
rs = command.ExecuteReader();
if(!rs.Read())
{
string message = !string.IsNullOrEmpty(this.whereClause) ? string.Format("could not read a hi value from table '{0}' using the where class ({1})- you need to populate the table"....//more statements);
TableGenerator.log.Error((object)message);
throw new IdentifierGeneratorException(message);
}
num1 = Convert.ToInt64(this.columnType.Get(rs, 0));
}
catch(Exception ex)
{
//more statements
}
//more statements
...
...
...
}
答案 0 :(得分:0)
instance.GeneratedBy.HiLo("NEXTHIVALUETABLE", "NEXTHIVALUECOLUMN", 10, builder =>
builder.AddParam("WHERE", string.Format("{0} = '{1}'", "TABLENAME", instance.EntityType.Name.ToUpperInvariant())));
我为WHERE制作大写,它解决了问题。非常奇怪的问题。