我尝试从https://github.com/jagregory/fluent-nhibernate/wiki/Getting-started运行示例,但在运行下一个代码后,所有表都被清除。我不明白为什么会这样。我希望将删除商店var barginBasin = new Store { Name = "Bargin Basin" };
以及此商店StoreProduct
的表Store_id
中的行。
using (var session = sessionFactory.OpenSession())
{
session.Delete(session.CreateCriteria(typeof (Store)).List<Store>()[0]);
session.Flush();
}
sessionFactory
初始化:
var dbConfig = OracleDataClientConfiguration.Oracle10
.ConnectionString(c => c.FromConnectionStringWithKey("Oracle"))
.Driver<OracleDataClientDriver>()
.ShowSql();
sessionFactory = Fluently.Configure()
.Database(dbConfig)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Employee>())
.BuildSessionFactory();
App.config中:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="Oracle"
connectionString="DATA SOURCE=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=[IP])(PORT=[PORT]))(CONNECT_DATA=(SERVICE_NAME=XE)));PASSWORD=[PASSWORD];PERSIST SECURITY INFO=True;USER ID=[USER ID]"
providerName="Oracle.DataAccess.Client" />
</connectionStrings>
</configuration>