【发布时间】:2011-07-16 09:39:29
【问题描述】:
如图所示,我将 hibernate.cfg.xml congif 文件放置在 PersistenceManager 项目中。
我需要以编程方式在此 getter 中设置此配置文件的物理路径以配置 NHibernate(带有 cfg.Configure 的行):
public class SessionService
{
private static ISessionFactory _sessionFactory = null;
public static ISessionFactory SessionFactory
{
get
{
if (_sessionFactory == null)
{
Configuration cfg = new Configuration();
string fullPath = (new SessionService()).GetType().Assembly.Location;
cfg.Configure(@"the working path to hibernate.cfg.xml");
//I will Add Mapping directives here
_sessionFactory = cfg.BuildSessionFactory();
}
return _sessionFactory;
}
}
}
如何仅通过键入字符串“hibernate.cfg.xml”并让 C# 生成物理路径的其余部分来安全地执行此操作?
【问题讨论】: