我正在研究NHibernate,当我测试它时,我尝试将所有数据列在我的Oracle数据库中。但NHibernate正确访问我的数据库,但删除我的所有数据,而不是只读取我的数据。NHibernate删除我的行
(我可以连接到数据库中,有与它没有任何问题,这只是它删除我的所有数据,而不要求它。)
这里是我的代码:
NHibernateSession:
public class NHibernateSession
{
public static ISession OpenSession()
{
return CreateSessionFactory().OpenSession();
}
private static ISessionFactory CreateSessionFactory()
{
var cfg = OracleClientConfiguration.Oracle9
.ConnectionString(c =>
c.Is("DATA SOURCE=xe.world;PERSIST SECURITY INFO=True;USER ID=apismart;Password=APISMART"));
var sessionFactory = Fluently.Configure()
.Database(cfg)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<MesureMap>().ExportTo(@".\"))
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
return sessionFactory;
}
private static void BuildSchema(NHibernate.Cfg.Configuration config)
{
new SchemaExport(config)
.Create(false, true);
}
}
}
得到我MesuresController:
public int Get()
{
using (ISession session = NHibernateSession.OpenSession())
{
RucheRepository repo = new RucheRepository(session);
IQueryable<Ruche> result = repo.GetAll();
return result.Count();
}
}
库:
public class RucheRepository : IRucheRepository
{
protected ISession Session;
public RucheRepository(ISession session)
{
this.Session = session;
}
public Ruche Get(int idRuche)
{
return Session.Query<Ruche>().Where(ruche => ruche.Id == idRuche).FirstOrDefault<Ruche>();
}
public IQueryable<Ruche> GetAll()
{
return Session.Query<Ruche>();
}
}
SchemaUpdate没有“.Create”方法:/ – Orionss
@Orionss对不起,我的意思是'执行',我更新了答案。 – Rabban
我工作!谢谢! – Orionss