I have a custom ID generator solution to support a legacy database that
inherits from TableGenerator. It is pretty simple the entire code is as
follows:
public class FDPSequence : TableGenerator
{
private const Int32 SeedValue = 1048576;
private static readonly ILog Log =
LogManager.GetLogger(typeof(FDPSequence));
public override object Generate(ISessionImplementor session, object
obj)
{
int counter = Convert.ToInt32(base.Generate(session, obj));
return counter + SeedValue + 1;
}
}
However, each table gets its counter from a different column of the same
table. So the configuration in FluentNH looks like this:
public InvestSpecMap()
{
WithTable("InvestSpec");
Id(x => x.Id).ColumnName("InvestSpecID")
.SetGeneratorClass(typeof(FDPSequence).AssemblyQualifiedName)
.AddGeneratorParam("table", "zSysCounters")
.AddGeneratorParam("column", "InvestSpec");
.
.
.
public PriceMap() {
WithTable("InvestPrice");
Id(x => x.Id).ColumnName("InvestPriceID")
.SetGeneratorClass(typeof(FDPSequence).AssemblyQualifiedName)
.AddGeneratorParam("table", "zSysCounters") //Name of the
FDP ID counter table
.AddGeneratorParam("column", "InvestPrice"); //FDP ID
counter
.
.
.
As you can see the InvestPrice table uses the InvestPrice column of the
zSysCounters table and the InvestSpec table uses the InvestSpec column.
However when I try to test using SQLite the DDL only creates one of the
columns:
create table zSysCounters (
InvestSpec INTEGER
)
which makes my tests on InvestPrice fail. I suppose this could be a problem
with FluentNH SessionSource.BuildSchema() though. I will try again with HBM
mappings instead unless someone has a better idea.
The setup is:
[SetUp]
public void SetupContext() {
var cfg = Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory()
.ProxyFactoryFactory("NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle")
.ShowSql());
SessionSource = new SessionSource(cfg.BuildConfiguration()
.Properties, new
TestModel());
Session = SessionSource.CreateSession();
SessionSource.BuildSchema(Session, true);
}
Thanks,
Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---