有谁能告诉我正确的语法?
我需要在我的代码中直接输入连接字符串才能进行单元测试。当连接字符串在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();
答案 0 :(得分:2)
删除lambda表达式:
MsSqlConfiguration.MsSql2008.ConnectionString(@"Data Source=localhost\try2;Initial Catalog=Northwind;Integrated Security=True")