static void Main(String[] args) { var cfg = new Configuration(); cfg.DataBaseIntegration(x => { x.Dialect <MsSql2008Dialect>(); x.Driver <Sql2008ClientDriver>(); x.ConnectionString = @"Data Source=(local)\SQLEXPRESS; Initial Catalog=NHibernate; Integrated Security=SSPI"; x.SchemaAction = SchemaAutoAction.Update; }) .SetProperty(NHibernate.Cfg.Environment.UseProxyValidator, Boolean.FalseString); var model = new ConventionModelMapper(); model.BeforeMapClass += (a, b, c) => { c.Lazy(false); c.Id(x => x.Generator(Generators.Identity)); }; var mappings = model.CompileMappingFor(new Type[] { typeof(Xpto) }); cfg.AddMapping(mappings); using (var sessionFactory = cfg.BuildSessionFactory()) { var validation = sessionFactory .FluentlyValidate() .Entity <Xpto>(x => x.Name != "aa", "Name is empty"); using (var session = sessionFactory.OpenSession()) using (var tx = session.BeginTransaction()) { var x = new Xpto(); try { session.Save(x); session.Flush(); } catch { //expected } x.Name = "aa"; //disable all validations //sessionFactory.DisableFluentValidation(); //disable validations over the Xpto class //validation.Clear<Xpto>(); //session.Save(new Xpto()); session.Flush(); //should work } } }
static void Main(String[] args) { var cfg = new Configuration(); cfg.DataBaseIntegration(x => { x.Dialect<MsSql2008Dialect>(); x.Driver<Sql2008ClientDriver>(); x.ConnectionString = @"Data Source=(local)\SQLEXPRESS; Initial Catalog=NHibernate; Integrated Security=SSPI"; x.SchemaAction = SchemaAutoAction.Update; }) .SetProperty(NHibernate.Cfg.Environment.UseProxyValidator, Boolean.FalseString); var model = new ConventionModelMapper(); model.BeforeMapClass += (a, b, c) => { c.Lazy(false); c.Id(x => x.Generator(Generators.Identity)); }; var mappings = model.CompileMappingFor(new Type[] { typeof(Xpto) }); cfg.AddMapping(mappings); using (var sessionFactory = cfg.BuildSessionFactory()) { var validation = sessionFactory .FluentlyValidate() .Entity<Xpto>(x => x.Name != "aa", "Name is empty"); using (var session = sessionFactory.OpenSession()) using (var tx = session.BeginTransaction()) { var x = new Xpto(); try { session.Save(x); session.Flush(); } catch { //expected } x.Name = "aa"; //disable all validations //sessionFactory.DisableFluentValidation(); //disable validations over the Xpto class //validation.Clear<Xpto>(); //session.Save(new Xpto()); session.Flush(); //should work } } }