sha*_*bus 5 sqlite nhibernate fluent-nhibernate nhibernate-configuration
我们有一个使用NHibernate/FluentNHibernate的应用程序,它MsSqlConfiguration.MsSql2008.ConnectionString指向我们的SQL环境.SQL服务器有几个数据库,我们可以使用如下的约定连接到不同的数据库:
public class FactseDatabaseConvention : IClassConvention
{
public void Apply(IClassInstance instance)
{
if (instance.EntityType.Namespace.EndsWith("Model.OtherEntities"))
{
instance.Schema("OtherDatabase.dbo");
}
}
}
Run Code Online (Sandbox Code Playgroud)
这有效,并生成正确的查询来访问OtherDatabase.当我们想要使用SQLiteConfiguration.Standard.InMemory()SessionFactory 进行测试时会出现问题.SQLite准备时,Persistence测试失败:
System.Data.SQLite.SQLiteException : SQL logic error or missing database
unknown database OtherDatabase
Run Code Online (Sandbox Code Playgroud)
这是它生成的命令:
create table OtherDatabse.dbo_my_other_entity_table (
Id UNIQUEIDENTIFIER not null,
... other properties
)
Run Code Online (Sandbox Code Playgroud)
有没有办法我可以改变我SQLiteConfiguration创建2个内存数据库,如果是这样,怎么样?或者我应该创建一个单独的会话来测试这些其他实体?
我遇到了同样的问题 - (自从我们从 Sqlite 迁移到 Sql Server LocalDB 进行测试后,就不再遇到这个问题了)。
我仍然有代码,我们所做的是提供一个配置是否使用模式的组件,因此:
public class SqlLiteMappingsHelper : IMappingsHelper
{
public string TextColumnTableSpecification
{
get
{
// see sqlite faqs re: all varchars are very large whatever you specify
// http://www.sqlite.org/faq.html#q9
return "nvarchar(10)";
}
}
public bool SchemasEnabled
{
get { return false; }
}
}
Run Code Online (Sandbox Code Playgroud)
(以及与 sql server 类似的一种SchemasEnabled = true) - 在 Web 应用程序中,您告诉 IoC 容器使用 sql server 容器,而在测试应用程序中,您使用 Sqlite 容器。然后在你的约定中:
public void Apply(IClassInstance instance)
{
var helper = IoC.get<IMappingsHelper>();
if (instance.EntityType.Namespace.EndsWith("Model.OtherEntities") && helper.SchemasEnabled)
{
instance.Schema("OtherDatabase.dbo");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1238 次 |
| 最近记录: |