Fluent Id field with two differents Database Engine (Oracle and SQL Server) [duplicate]
I'm using Fluent NHibernate to map my entities.
In my application I have to work with 2 different engines (Oracle and SQL Server). I set the engine with the parameter in the command line argument and send it to my SessionFactory class:
public static ISessionFactory CreateSessionFactory(string databaseEngine, string connectionString, Type entityType)
{
switch (databaseEngine.ToLower())
{
case "mssql":
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(connectionString))
.Mappings(m => m.FluentMappings.AddFromAssembly(entityType.Assembly))
.BuildSessionFactory();
case "oracle":
return Fluently.Configure()
.Database(OracleClientConfiguration.Oracle9.ConnectionString(connectionString))
.Mappings(m => m.FluentMappings.AddFromAssembly(entityType.Assembly))
.BuildSessionFactory();
}
return null;
}
This is one of my MapClass:
public class SimulacaoMap : ClassMap<Simulacao>
{
public SimulacaoMap()
{
Table("SIMULACAO").GeneratedBy.Sequence("SEQUENCE_NAME");
Id(x => x.Id).Column("ID_SIMULACAO");
Map(x => x.DataReferencia).Column("DAT_REFERENCIA");
}
}
This works for Oracle, but, when I use SQL Server I get this exception:
could not instantiate id generator: sequence.
How can I use a Id Map that works for SQL Server and Oracle at the same time?
Thanks
SQL Server vNext supports "SEQUENCE", or change that "GeneratedBy" part.
精彩评论