本文整理汇总了C#中NHibernate.Cfg.Configuration.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.Initialize方法的具体用法?C# Configuration.Initialize怎么用?C# Configuration.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Cfg.Configuration
的用法示例。
在下文中一共展示了Configuration.Initialize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main(string[] args)
{
XmlConfigurator.Configure();
var log = LogManager.GetLogger(typeof (Program));
SetupNHibernateValidator();
var nhibernateConfig = new Configuration().Configure();
nhibernateConfig.Initialize();
ISessionFactory sessionFactory = nhibernateConfig.BuildSessionFactory();
var schemaExport = new SchemaExport(nhibernateConfig);
schemaExport.Execute(false, true, false);
var junk = new Product
{
Name = "Spiffy Junk",
Description = string.Empty,
UnitPrice = -1M
};
var ve = Environment.SharedEngineProvider.GetEngine();
var invalidValues = ve.Validate(junk);
foreach (var invalidValue in invalidValues)
log.InfoFormat("{0} {1}",
invalidValue.PropertyName,
invalidValue.Message);
}
示例2: Main
static void Main(string[] args)
{
XmlConfigurator.Configure();
var log = LogManager.GetLogger(typeof(Program));
SetupNHibernateValidator();
var cfg = new Configuration().Configure();
cfg.Initialize();
var sessionFactory = cfg.BuildSessionFactory();
var schemaExport = new SchemaExport(cfg);
schemaExport.Execute(true, true, false);
var junk = new Product
{
Name = "Spiffy Junk",
Description = "Stuff we can't sell.",
UnitPrice = -1M
};
using (var session = sessionFactory.OpenSession())
{
using (var tx = session.BeginTransaction())
{
try
{
session.Save(junk);
tx.Commit();
}
catch (InvalidStateException validationException)
{
var errors = validationException.GetInvalidValues();
foreach (var error in errors)
log.ErrorFormat("Error with property {0}: {1}",
error.PropertyName, error.Message);
tx.Rollback();
}
}
}
}
示例3: CreateSessionFactory
private static ISessionFactory CreateSessionFactory(IKernel kernel)
{
var validatorEngine = kernel.Resolve<ValidatorEngine>();
Assert.NotNull(typeof(System.Data.SQLite.SQLiteConnection));
_nhConfig = new NHibernate.Cfg.Configuration()
.SetProperty(NHibernate.Cfg.Environment.CurrentSessionContextClass, typeof(ConversationSessionContext).AssemblyQualifiedName)
.SetProperty(Environment.ConnectionDriver, typeof(SQLite20Driver).AssemblyQualifiedName)
.SetProperty(Environment.Dialect, typeof(SQLiteDialect).AssemblyQualifiedName)
.SetProperty(Environment.ConnectionString, "Data Source=:memory:")
.SetProperty(Environment.ProxyFactoryFactoryClass, typeof(ProxyFactoryFactory).AssemblyQualifiedName)
.SetProperty(Environment.ReleaseConnections, "on_close")
.SetProperty(Environment.UseSecondLevelCache, "true")
.SetProperty(Environment.UseQueryCache, "true")
.SetProperty(Environment.CacheProvider, typeof(HashtableCacheProvider).AssemblyQualifiedName)
.AddAssembly(typeof(User).Assembly);
Security.Configure<User>(_nhConfig, SecurityTableStructure.Prefix);
_nhConfig.Initialize(validatorEngine);
return _nhConfig.BuildSessionFactory();
}
示例4: ConfigureValidator
/// <summary>
/// Configura o validados do nhibernate para validar as classes do dominio
/// </summary>
/// <param name="nHibernateConfiguration"></param>
/// <returns></returns>
private static ValidatorEngine ConfigureValidator(Configuration nHibernateConfiguration)
{
var configure = new NHibernate.Validator.Cfg.Loquacious.FluentConfiguration();
configure.Register(
Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.Namespace != null && t.Namespace.Equals("Progas.Portal.Factory.Entity"))
.ValidationDefinitions())
.SetDefaultValidatorMode(ValidatorMode.UseAttribute)
.IntegrateWithNHibernate.ApplyingDDLConstraints().And.RegisteringListeners();
var ve = new ValidatorEngine();
ve.Configure(configure);
nHibernateConfiguration.Initialize(ve);
return ve;
}
示例5: injectValidationAndFieldLengths
private void injectValidationAndFieldLengths(Configuration nhConfig)
{
if (string.IsNullOrWhiteSpace(ValidationDefinitionsNamespace))
return;
MappingsValidatorEngine = new ValidatorEngine();
var configuration = new FluentConfiguration();
var validationDefinitions = MappingsAssembly.GetTypes()
.Where(t => t.Namespace == ValidationDefinitionsNamespace)
.ValidationDefinitions();
configuration
.Register(validationDefinitions)
.SetDefaultValidatorMode(ValidatorMode.OverrideExternalWithAttribute)
.IntegrateWithNHibernate
.ApplyingDDLConstraints()
.And
.RegisteringListeners();
MappingsValidatorEngine.Configure(configuration);
//Registering of Listeners and DDL-applying here
nhConfig.Initialize(MappingsValidatorEngine);
}