开发者

Fluent Id field with two differents Database Engine (Oracle and SQL Server) [duplicate]

This question already has an a开发者_开发技巧nswer here: how to Unit test fluent mappings, with in memory sqlite when you got sequences (1 answer) Closed 2 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜