2011-11-19 55 views
2

任何人都可以告訴我正確的語法嗎?Conn。Nhibernate Config流利。在web.config中的字符串,但不是

我需要在我的代碼中直接輸入連接字符串才能進行單元測試。一切工作正常時,連接字符串是在web.config文件:

<add name="SQLNorthwindConnectionString" connectionString="Data Source=localhost\try2;Initial Catalog=Northwind;Integrated Security=True" providerName="System.Data.SqlClient"/> 

在代碼中使用它:

_SessionFactory = Fluently.Configure(). 
Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("SQLNorthwindConnectionString")). 
ShowSql(). 
Cache(c => c.ProviderClass<SysCacheProvider>(). UseQueryCache())). 
Mappings(m => m.FluentMappings.AddFromAssemblyOf<FNHibernateHelperSQLite>().Conventions.AddFromAssemblyOf<NorthwindMVCApp.FNHibernate.CustomForeignKeyConvention>()). 
BuildSessionFactory(); 

但是,這並不工作:

_SessionFactory = Fluently.Configure(). 
Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.Is("Data Source=localhost\try2;Initial Catalog=Northwind;Integrated Security=True")). 
ShowSql(). 
Cache(c => c.ProviderClass<SysCacheProvider>().UseQueryCache())). 
Mappings(m => m.FluentMappings.AddFromAssemblyOf<FNHibernateHelperSQLite>().Conventions.AddFromAssemblyOf<NorthwindMVCApp.FNHibernate.CustomForeignKeyConvention>()). 
BuildSessionFactory(); 

回答

2

刪除拉姆達表達:

MsSqlConfiguration.MsSql2008.ConnectionString(@"Data Source=localhost\try2;Initial Catalog=Northwind;Integrated Security=True") 
+0

它的工作表示感謝。 –

相關問題