问题描述
我试图运行使用SQLite在我的映射一些测试。我的映射如下所示:
I am trying to run some tests on my mapping using SQLite. My mappings look like the following:
public class UserMap : BaseValidatableDomainMap<User>
{
public UserMap()
{
Table("blanka.[User]");
Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.UserName);
Map(x => x.FirstName);
Map(x => x.MiddleName);
Map(x => x.LastName);
Map(x => x.EmailAddress);
Map(x => x.OtherEmailAddress);
Map(x => x.PhoneNumber);
Map(x => x.City);
References(x => x.Company, "CompanyId");
References(x => x.State, "StateId");
}
}
这样做的问题是,布兰卡导致下面的配置失败。如果我从我的映射测试通过删除布兰卡
模式,但很明显我的映射停在我的真正的应用程序的工作。有没有一种方法,以消除来自我的映射布兰卡
模式在下面的设置代码的地方?或者是有没有办法设置的SQLite与它合作?
The problem with this is that blanka causes the configuration below to fail. If I remove the blanka
schema from my mapping my tests pass, but obviously my mappings stop working in my real app. Is there a way to remove the blanka
schema from my mapping in the somewhere in the setup code below? Or is there a way to setup SQLite to work with it?
static ISessionFactory BuildSessionFactory()
{
return Fluently.Configure()
.Database(SQLiteConfiguration.Standard.UsingFile(DB_FILE_NAME))
.Mappings(m => m.FluentMappings.Add<UserMap>())
.Mappings(m => m.FluentMappings.Add<CompanyMap>())
.Mappings(m => m.FluentMappings.Add<StateMap>())
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}
static void BuildSchema(NHibernate.Cfg.Configuration cfg)
{
if (File.Exists(DB_FILE_NAME))
File.Delete(DB_FILE_NAME);
new SchemaExport(cfg).Create(false, true);
}
更新
这里是我结束了固定的:
Update
Here is how I ended up fixing this:
我删除了我的用户映射的架构,使它看起来像这样:
I removed the schema from my UserMap so that it looked like this:
public class UserMap : BaseValidatableDomainMap<User>
{
public UserMap()
{
Table("[User]");
Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.UserName);
Map(x => x.FirstName);
Map(x => x.MiddleName);
Map(x => x.LastName);
Map(x => x.EmailAddress);
Map(x => x.OtherEmailAddress);
Map(x => x.PhoneNumber);
Map(x => x.City);
References(x => x.Company, "CompanyId");
References(x => x.State, "StateId");
}
}
然后,我改变我的应用程序的配置设置默认模式到布兰卡它看起来像这样:
Then I changed my app configuration to set the default schema to blanka which looks like this:
private static ISessionFactory CreateSessionFactory()
{
var config = Fluently.Configure();
config = config.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("BLANKADB")).DefaultSchema("blanka"))
.ExposeConfiguration( c => c.SetProperty("current_session_context_class", "web"))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<BlankaObject>());
return config.BuildSessionFactory();
}
和我单独留下我的SQLite测试的配置,因为它讨厌模式。 = D
And I left my SQLite test config alone because it hates schemas. =D
推荐答案
怎么样使用DEFAULT_SCHEMA配置属性(我知道这是在配置,不知道随便怎么流利设置的),而不是把它在类的映射。
What about using the default_schema configuration property (I know it's in the config, not sure offhand how to set it fluently) instead of putting it in class mapping.
这篇关于功能NHibernate - 从映射试验删除模式使用SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!