public MyAutoPersistenceModel() { this.AutoPersistenceModel = AutoMap.AssemblyOf <Entity>(new CustomAutomappingConfiguration()) .IgnoreBase <Entity>() .Override <User>(map => map.IgnoreProperty(x => x.DisplayedName)) .Override <Appointment>(map => map.IgnoreProperty(x => x.DateRange)) .Override <IllnessPeriod>(map => map.IgnoreProperty(p => p.Duration)) .Override <Role>(map => map.HasManyToMany(x => x.Tasks).Cascade.All()) .Override <DbSetting>(map => map.Map(p => p.Key).Unique()) .Override <Patient>(map => { map.DynamicUpdate(); map.IgnoreProperty(x => x.Age); map.Map(x => x.IsDeactivated).Default("0").Not.Nullable(); map.HasMany <Bmi>(x => x.BmiHistory).KeyColumn("Patient_Id"); map.HasMany <MedicalRecord>(x => x.MedicalRecords).KeyColumn("Patient_Id"); map.HasMany <IllnessPeriod>(x => x.IllnessHistory).KeyColumn("Patient_Id"); map.HasMany <Appointment>(x => x.Appointments).KeyColumn("Patient_Id"); }) .Override <Person>(map => { map.Map(p => p.FirstName).Index("idx_person_FirstName"); map.Map(p => p.LastName).Index("idx_person_LastName"); }) .Override <ApplicationStatistics>(map => { map.Map(e => e.IsExported).Default("0").Not.Nullable(); map.Map(e => e.Version).Default("\"3.0.3\"").Not.Nullable(); }) .Conventions.Add(DefaultCascade.SaveUpdate() , DynamicUpdate.AlwaysTrue() , DynamicInsert.AlwaysTrue() , LazyLoad.Always()); }
public Action <MappingConfiguration> MappingConfiguration() { return(m => m.FluentMappings.AddFromAssemblyOf <Entity>() .Conventions.Add(ForeignKey.EndsWith("Id")) .Conventions.Add(DefaultLazy.Always()) .Conventions.Add(DefaultCascade.SaveUpdate())); }
// Returns our mappings private static AutoPersistenceModel CreateMappings() { return(AutoMap .Assembly(System.Reflection.Assembly.GetCallingAssembly()) .Where(t => t.Namespace != null && t.Namespace.EndsWith("Models")) .Conventions.Setup(c => c.Add(DefaultCascade.SaveUpdate()))); }
// Returns our mappings private static AutoPersistenceModel CreateMappings() { return(AutoMap .Assembly(System.Reflection.Assembly.GetCallingAssembly()) .Where(t => t.Namespace == "FluentNHibernateConsole.Entities") .Conventions.Setup(c => c.Add(DefaultCascade.SaveUpdate()))); }
public ISessionFactory CreateFactory(string connectionString) { var nhibcfg = new NHibernate.Cfg.Configuration(); var cfg = Fluently.Configure(nhibcfg) .Database( PostgreSQLConfiguration .Standard .ConnectionString(connectionString) ) .Mappings(m => { m.AutoMappings.Add(AutoMap.AssemblyOf <Banan>(new AutomappingConfiguration()) .Conventions.Setup ( con => { con.Add <CommonConventions>(); con.Add(DefaultLazy.Never()); con.Add(DefaultCascade.SaveUpdate()); con.Add(DynamicInsert.AlwaysTrue()); con.Add(DynamicUpdate.AlwaysTrue()); }).UseOverridesFromAssemblyOf <OvverideMappingsFatherBanan>()); m.FluentMappings.Conventions.Add <CommonConventions>(); m.FluentMappings.Conventions.Add(DefaultLazy.Never(), DefaultCascade.SaveUpdate(), DynamicInsert.AlwaysTrue(), DynamicUpdate.AlwaysTrue()); m.MergeMappings(); }); if (true) { var directory = $"BananFatherDatabase.HBM"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } cfg.Mappings(m => m.AutoMappings.ExportTo(directory)); } cfg.ExposeConfiguration(c => SchemaMetadataUpdater.QuoteTableAndColumns(c, new PostgreSQLDialect())); cfg.ExposeConfiguration(c => c.SetProperty("command_timeout", "30")); cfg.ExposeConfiguration(x => { x.SetInterceptor(new SqlStatementInterceptor()); }); UpdateSchema(cfg.BuildConfiguration()); return(cfg.BuildSessionFactory()); }
private static AutoPersistenceModel CreateAutomappings() { // This is the actual automapping - use AutoMap to start automapping, // then pick one of the static methods to specify what to map (in this case // all the classes in the assembly that contains Employee), and then either // use the Setup and Where methods to restrict that behaviour, or (preferably) // supply a configuration instance of your definition to control the automapper. return(AutoMap.AssemblyOf <User>() .Where(o => o.Namespace != null && o.Namespace.EndsWith("DemoProject.Domain.Model")) .Conventions.Add <CustomClassNameConvention>() .Conventions.Add <CustomPropertyConvention>() .Conventions.Add <CustomPrimaryKeyConvention>() .Conventions.Add <CustomCollectionConvention>() .Conventions.Add <CustomReferenceConvention>() .Conventions.Add <CustomManyToManyConvention>() .Conventions.Add(DefaultCascade.SaveUpdate())); }
private AutoPersistenceModel CreateMappings() { var mappingSetup = AutoMap .AssemblyOf <TEntity>() .Where(x => !typeof(IAutoMapperSettings).IsAssignableFrom(x) && //ignore all classes that implement auto mapper settings. !x.IsSubclassOf(typeof(BaseRepo)) && //ignore all classes that inherit from nhibernate base repo class !x.IsSubclassOf(typeof(RepoSplit <TEntity, TOverride>)) && //ignore all classes that inherit from nhibernate repo class !x.IsSubclassOf(typeof(RepoCombined <TEntity>)) && //ignore all classes that inherit from nhibernate repo class !typeof(IClassConvention).IsAssignableFrom(x) && //ignore all NHibernate convention classes !x.IsSubclassOf(typeof(AbstractBaseMigration)) && //ignore all migration files. !x.IsSubclassOf(typeof(RepoMigrationConfigurationBaseNoneGeneric)) //ignore all migration configuration files. ) .Conventions.AddFromAssemblyOf <TOverride>() .UseOverridesFromAssemblyOf <TOverride>() .Conventions.Add(DefaultLazy.Never()) .Conventions.Add(DefaultCascade.SaveUpdate()); return(mappingSetup); }
private static ISessionFactory CreateSessionFactory() { _sessionFactory = Fluently.Configure() .Database(FluentNHibernate.Cfg.Db.MsSqlCeConfiguration.Standard.ShowSql() .ConnectionString(c => c.FromConnectionStringWithKey("DbConnectionString"))) .Mappings(m => m.FluentMappings.AddFromAssemblyOf <Task.TaskMap>().Conventions.Add(DefaultCascade.SaveUpdate())) .Mappings(m => m.FluentMappings.AddFromAssemblyOf <User.UserMap>().Conventions.Add(DefaultCascade.SaveUpdate())) .Mappings(m => m.FluentMappings.AddFromAssemblyOf <TaskCategory.TaskCategoryMap>().Conventions.Add(DefaultCascade.None())) .BuildSessionFactory(); return(_sessionFactory); }