本文整理汇总了C#中Configuration.Configure方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.Configure方法的具体用法?C# Configuration.Configure怎么用?C# Configuration.Configure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Configuration
的用法示例。
在下文中一共展示了Configuration.Configure方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDefaultConfiguration
/// <summary>
/// Standar Configuration for tests.
/// </summary>
/// <returns>The configuration using merge between App.Config and hibernate.cfg.xml if present.</returns>
public static Configuration GetDefaultConfiguration()
{
Configuration result = new Configuration();
if (hibernateConfigFile != null)
result.Configure(hibernateConfigFile);
return result;
}
示例2: BuildSessionFactory
/// <summary>
/// Builds the session factory.
/// </summary>
/// <param name="sources">The <see cref="IEnumerable{T}"/> of <see cref="System.Reflection.Assembly"/> sources.</param>
/// <param name="configurationFile">The configuration file.</param>
public static void BuildSessionFactory(IEnumerable<Assembly> sources, string configurationFile = null)
{
if (Factory != null)
{
return;
}
Log.Info("Building SessionFactory");
lock (lck)
{
Configuration = new Configuration();
Configuration.Configure(configurationFile ?? CreateConfigurationFile());
Factory = Fluently.Configure(Configuration).Mappings(m =>
{
foreach (var assembly in sources)
{
Log.Info(x => x("Adding Mappings from assembly: {0}", assembly.FullName));
m.FluentMappings.AddFromAssembly(assembly);
}
})
.ExposeConfiguration(xConf => xConf.SetListener(global::NHibernate.Event.ListenerType.Delete, new DeleteEventListener()))
.BuildSessionFactory();
}
}
示例3: MainWindow
public MainWindow()
: base(Gtk.WindowType.Toplevel)
{
Build ();
Configuration configuration = new Configuration();
configuration.Configure();
configuration.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlKeyWords, "none");
configuration.AddAssembly(typeof(Categoria).Assembly);
new SchemaExport(configuration).Execute(true, false, false);
ISessionFactory sessionFactory = configuration.BuildSessionFactory();
//updateCategoria(sessionFactory);
//insertCategoria(sessionFactory);
//loadArticulo(sessionFactory);
ISession session = sessionFactory.OpenSession();
ICriteria criteria = session.CreateCriteria(typeof(Articulo));
criteria.SetFetchMode("Categoria", FetchMode.Join);
IList list = criteria.List();
foreach (Articulo articulo in list)
Console.WriteLine("Articulo Id={0} Nombre={1} Precio={2} Categoria={3}",
articulo.Id, articulo.Nombre, articulo.Precio, articulo.Categoria);
session.Close();
sessionFactory.Close();
}
示例4: MainWindow
public MainWindow()
: base(Gtk.WindowType.Toplevel)
{
Build ();
Configuration configuration = new Configuration();
configuration.Configure ();
configuration.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlKeyWords, "none");
configuration.AddAssembly(typeof(Categoria).Assembly);
ISessionFactory sessionFactory = configuration.BuildSessionFactory();
updateCategoria(sessionFactory);
insertCategoria(sessionFactory);
//new SchemaExport(configuration).Execute(true, false, false);
/*ISession session = sessionFactory.OpenSession();
Categoria categoria = (Categoria)session.Load(typeof(Categoria), 2L);
Console.WriteLine("Categoria Id={0} Nombre={1}", categoria.Id, categoria.Nombre);
categoria.Nombre = DateTime.Now.ToString ();
session.SaveOrUpdate (categoria);
session.Flush ();
session.Close ();*/
try{
ISession session = sessionFactory.OpenSession();
ICriteria criteria = session.CreateCriteria (typeof(/*Categoria*/articulo));
IconList list = criteria.List ();
foreach(/*Categoria categoria*/Articulo articulo in list)
Console.WriteLine ("Articulo Id={0} Nombre={1} Precio{2}",/*categoria*/articulo.Id, /*categoria*/articulo.Nombre, articulo.Precio);
}finally{
sessionFactory.Close();
}
sessionFactory.Close ();
}
示例5: MainWindow
public MainWindow()
: base(Gtk.WindowType.Toplevel)
{
Build ();
//http://darioquintana.com.ar/articles/tutorial-de-nhibernate-primeros-pasos
//http://nhforge.org/doc/nh/en/index.html
//Clase configuration de NHibernate
Configuration configuration = new Configuration();
configuration.Configure();
configuration.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlKeyWords, "none");
configuration.AddAssembly(typeof(Categoria).Assembly);
/*new SchemaExport(configuration).execute(true,false,false);*/
//Se encarga crear sesiones en nuestra aplicacion.
ISessionFactory sessionFactory = configuration.BuildSessionFactory ();
ISession session = sessionFactory.OpenSession();
ICriteria criteria = session.CreateCriteria (typeof(Articulo));
criteria.SetFetchMode("Categoria", FetchMode.Join);
IList list = criteria.List();
foreach (Articulo articulo in list)
Console.WriteLine("Articulo Id={0} Nombre={1} Precio={2} Categoria={3}",
articulo.Id, articulo.Nombre, articulo.Precio, articulo.Categoria);
session.Close ();
}
示例6: MainWindow
public MainWindow()
: base(Gtk.WindowType.Toplevel)
{
Build ();
Configuration configuration = new Configuration();
configuration.Configure ();
configuration.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlKeyWords, "none");
configuration.AddAssembly(typeof(Categoria).Assembly);
new SchemaExport(configuration).Execute(true, false, false);
ISessionFactory sessionFactory = configuration.BuildSessionFactory ();
//insertCategoria(sessionFactory);
using (ISession session = sessionFactory.OpenSession()) {
ICriteria criteria = session.CreateCriteria(typeof(Categoria));
IList list = criteria.List();
foreach (Categoria categoria in list) {
Console.WriteLine("Categoria Id={0} Nombre={1}", categoria.Id, categoria.Nombre);
}
}
sessionFactory.Close();
}
示例7: NHibernateSession
public NHibernateSession()
{
Assembly assembly = typeof(NHibernateSession).Assembly;
configuration = new Configuration();
configuration.Configure();
configuration.AddAssembly(assembly);
factory = configuration.BuildSessionFactory();
}
示例8: init
public void init()
{
cfg = new Configuration();
cfg.Configure();
/* Add xml mappings created manually
* - Because Web Site projects are only compiled during runtime, the hibernate mapping files will need to
* be discovered and added to the assembly at runtime.
*/
cfg.AddDirectory(new DirectoryInfo(HttpContext.Current.Server.MapPath("~/Mapping")));
//Add your custom configurations here to override the Hibernate.xml configuration.
}
示例9: MainWindow
public MainWindow()
: base(Gtk.WindowType.Toplevel)
{
Build ();
Configuration configuration = new Configuration();
configuration.Configure();
configuration.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlKeyWords,"none");
configuration.AddAssembly(typeof(Categoria).Assembly);
new SchemaExport(configuration).Execute(true,false,false);
ISessionFactory sessionFactory=configuration.BuildSessionFactory();
// updateCategoria(sessionFactory);
//insertCategoria(sessionFactory);
loadArticulo(sessionFactory);
sessionFactory.Close();
}
示例10: MsSqlDaoFactory
public MsSqlDaoFactory()
{
Configuration config = new Configuration();
config.Configure();
this.sessionFactory = config.BuildSessionFactory();
}
示例11: NHSessionManager
static NHSessionManager()
{
try
{
Configuration cfg = new Configuration();
string configFile = @"hibernate.cfg.xml";
string mappingPath = PathFunctions.GetMappingPath();
cfg.Configure(Path.Combine(mappingPath, configFile));
foreach (string file in Directory.GetFiles(mappingPath, "*.hbm.xml"))
cfg.AddXmlFile(file);
factory = cfg.BuildSessionFactory();
}
catch(Exception ex)
{
Log.Add(ex.ToString());
}
}
示例12: ConfigureNHibernate
private static Configuration ConfigureNHibernate(string cfgFile, IDictionary<string, string> cfgProperties)
{
var cfg = new Configuration();
if (cfgProperties != null)
{
cfg.AddProperties(cfgProperties);
}
if (string.IsNullOrEmpty(cfgFile) == false)
{
return cfg.Configure(cfgFile);
}
if (File.Exists("Hibernate.cfg.xml"))
{
return cfg.Configure();
}
return cfg;
}
示例13: NHSessionManager
static NHSessionManager()
{
try
{
Configuration cfg = new Configuration();
string configFile = Helper.IsDevelopment()
? @"hibernate.debug.cfg.xml"
: @"hibernate.cfg.xml";
string mappingPath = PathFunctions.GetMappingPath();
cfg.Configure(Path.Combine(mappingPath, configFile));
foreach (string file in Directory.GetFiles(mappingPath, "*.hbm.xml"))
cfg.AddXmlFile(file);
factory = cfg.BuildSessionFactory();
}
catch
{
}
}