FluentNhibernate support for SQL Server 2008 R2

2019-04-15 17:11发布

I want to implement a Fluent Nhibernate application with SQL Server 2008 R2.

I am in a confusion whether Fluent Nhibernate 1.2 supports SQL Server 2008 R2.

If supports what will be the configuration. Does it looks like below?

var config = Fluently.Configure()
                .Database(
                    MsSqlConfiguration
                    .MsSql2008R2
                    .ConnectionString(@"Data Source=.\SQLEXPRESS;AttachDbFilename='FNHLD.mdf';Integrated Security=True;User Instance=True"))
                    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<NHibernateRepository<T>>())
                .BuildConfiguration();

3条回答
【Aperson】
2楼-- · 2019-04-15 17:34

I also use MsSqlConfiguration.MsSql2008. Going through the release notes for 2008R2 I cant see any features that would require a different dialect.

查看更多
仙女界的扛把子
3楼-- · 2019-04-15 17:37

Actually I use this configuration for connect to an SQL Server 2008 R2 SP1 Database without problems:

            var nhConfig = Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2008
                          .ConnectionString(connstr => connstr.FromConnectionStringWithKey("DBConnectionString"))
                          .ShowSql())//<-I use this for debug
            .Cache(c => c
                            .UseQueryCache()
                            .UseMinimalPuts()
                            .ProviderClass<HashtableCacheProvider>())//<--Cache Level Two
            .Mappings(m => m.FluentMappings
                               .AddFromAssemblyOf<Avaruz.Artemisa.Domain.Apm>())
            .CurrentSessionContext<WebSessionContext>()
            .BuildConfiguration();
查看更多
萌系小妹纸
4楼-- · 2019-04-15 17:55

As a matter of fact, even MsSql2005 dialect will work on SQL Server 2008 R2.

Ie, if you use MsSql2005 dialect on SQL Server 2008 database, NHibernate only won't be able to use some additional types regarding date/times that are new to SQL Server 2008.

Just for fun, here are the links to the source code of 2000-2012 SQL Server dialects:

MsSql2000
MsSql2005
MsSql2008
MsSql2012

You can see the pattern there. MsSql2000 is kind of a main dialect. MsSql2005 inherits from MsSql2005 and has a couple of overrides. MsSql2008 inherits from MsSql2005, also with few overrides. MsSql2012 inherits from MsSql2008.

SQL Server R2 is kind of like a service pack. Not much has changed in the database engine itself, so there wasn't a need to have a separate dialect. Use either 2005 or 2008 dialect and you will be fine.

查看更多
登录 后发表回答