protected virtual void AdditionalModelConfig(AutoPersistenceModel model) { // 29.12.2011 - Who would have thought that apparently only know I managed to surpass 4000 chars. // seems crazy but anyways, here's a fix for NH cutting off my text model.Override<Content>( a => a.Map(c => c.Body).Length(4001).CustomSqlType("nvarchar(MAX)")); }
public static Configuration Init( ISessionStorage storage, string[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, string cfgFile, IDictionary <string, string> cfgProperties, string validatorCfgFile, IPersistenceConfigurer persistenceConfigurer) { InitStorage(storage); try { return(AddConfiguration( DefaultFactoryKey, mappingAssemblies, autoPersistenceModel, cfgFile, cfgProperties, validatorCfgFile, persistenceConfigurer)); } catch { // If this NHibernate config throws an exception, null the Storage reference so // the config can be corrected without having to restart the web application. Storage = null; throw; } }
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 AutoMappingTester(AutoPersistenceModel mapper) : base(mapper) { mapper.CompileMappings(); ForMapping((ClassMap <T>)null); }
/// <summary> Configure domain mapping </summary> public static AutoPersistenceModel ConfigureMapping(Configuration configuration) { AutoPersistenceModel model = Mapping.CreateMapping(); model.Configure(configuration); return(model); }
public void Alter(AutoPersistenceModel model) { model.Override <Document>(mapping => { // todo: study the gains on using HiLo // mapping.Id(x => x.Id).GeneratedBy.HiLo("100"); mapping.Map(x => x.Type).Index("idx_document_type"); mapping.Map(x => x.Content).Length(4001); foreach (var index in _hasDocumentsIndexes) { var type = typeof(HasManyAlteration <>).MakeGenericType(index); var alteration = (IAlteration)Activator.CreateInstance(type); alteration.Override(mapping); } foreach (var index in _hasDocumentIndexes) { var type = typeof(HasOneAlteration <>).MakeGenericType(index); var alteration = (IAlteration)Activator.CreateInstance(type); alteration.Override(mapping); } }); }
/// <summary> /// Called when an empty fluent configuration object has been created, /// before applying any default Boying config settings (alterations, conventions etc.). /// </summary> /// <param name="cfg">Empty fluent NH configuration object.</param> /// <param name="defaultModel">Default persistence model that is about to be used.</param> public override void Created(FluentConfiguration cfg, AutoPersistenceModel defaultModel) { defaultModel.OverrideAll(map => { map.IgnoreProperties(x => x.MemberInfo.IsDefined(typeof(DoNotMapAttribute), false)); }); }
/// Called when an empty fluent configuration object has been created, /// before applying any default Orchard config settings (alterations, conventions etc.). ///Empty fluent NH configuration object. ///Default persistence model that is about to be used. //https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Fluent-mapping //https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Auto-mapping //https://tpodolak.com/blog/2013/03/25/fluent-nhibernate-automappings/ //http://www.ideliverable.com/blog/isessionconfigurationevents public void Created(FluentConfiguration cfg, AutoPersistenceModel defaultModel) { //https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Auto-mapping //https://daveden.wordpress.com/2012/04/05/how-to-use-fluent-nhibernate-with-auto-mappings/ //https://stackoverflow.com/questions/42100286/nhibernate-fluent-add-external-assembly-mappings //https://stackoverflow.com/questions/1858245/fluent-nhibernate-how-to-tell-it-not-to-map-a-base-class }
private static ISessionFactory BuildSessionFactory() { AutoPersistenceModel model = CreateMappings(); return(Fluently.Configure() .Database(MsSqlConfiguration.MsSql2005 .ConnectionString(c => c .Server("MYCOMPUTER\\SQLEXPRESS") .Database("testdb") .Username("test") .Password("test"))) .Mappings(m => m .AutoMappings.Add(model)) .ExposeConfiguration(BuildSchema) .BuildSessionFactory()); }
private void CreateFluentConfiguration(AutoPersistenceModel autoPersistenceModel) { try { Fluently.Configure(_configuration) .Mappings(m => m.AutoMappings.Add(autoPersistenceModel)) #if DEBUG // .ExportTo(@"C:\temp\")) #endif .BuildConfiguration() .CurrentSessionContext <ThreadLocalConversationalSessionContext>() ; } catch (ReflectionTypeLoadException ex) { var sb = new StringBuilder(); foreach (Exception exSub in ex.LoaderExceptions) { sb.AppendLine(exSub.Message); if (exSub is FileNotFoundException) { var exFileNotFound = exSub as FileNotFoundException; if (!string.IsNullOrEmpty(exFileNotFound.FusionLog)) { sb.AppendLine("Fusion Log:"); sb.AppendLine(exFileNotFound.FusionLog); } } sb.AppendLine(); sb.AppendLine(ex.ToString()); } var errorMessage = sb.ToString(); _logWriter.Error(EventIds.BACKEND_SERVER_DOWN, "CreateFluentConfiguration: " + errorMessage); } }
public void Configure(Configuration configuration) { var autoPersistenceModel = new AutoPersistenceModel(this.autoMappingConfiguration); foreach (var conventionType in this.conventionTypes) { autoPersistenceModel.Conventions.Add(conventionType); } foreach (var assembly in this.autoMapAssemblies) { autoPersistenceModel.AddEntityAssembly(assembly); } foreach (var assembly in this.overrideAssemblies) { autoPersistenceModel.UseOverridesFromAssembly(assembly); } foreach (var @override in this.overrides) { @override(autoPersistenceModel); } autoPersistenceModel.Configure(configuration); }
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 static AutoPersistenceModel SagaPersistenceModel(IEnumerable<Type> typesToScan) { var sagaEntites = typesToScan.Where(t => typeof(ISagaEntity).IsAssignableFrom(t) && !t.IsInterface); var model = new AutoPersistenceModel(); model.Conventions.AddFromAssemblyOf<IdShouldBeAssignedConvention>(); var entityTypes = GetTypesThatShouldBeAutoMapped(sagaEntites,typesToScan); var assembliesContainingSagas = sagaEntites.Select(t => t.Assembly).Distinct(); foreach (var assembly in assembliesContainingSagas) model.AddEntityAssembly(assembly) .Where(t => entityTypes.Contains(t)); var componentTypes = GetTypesThatShouldBeMappedAsComponents(sagaEntites); model.Setup(s => { s.IsComponentType = type => componentTypes.Contains(type); }); return model; }
private static ISessionFactory CreateSessionFactoryFor( string[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, Configuration cfg, IPersistenceConfigurer persistenceConfigurer) { FluentConfiguration fluentConfiguration = Fluently.Configure(cfg); if (persistenceConfigurer != null) { fluentConfiguration.Database(persistenceConfigurer); } fluentConfiguration.Mappings(m => { foreach (var mappingAssembly in mappingAssemblies) { var assembly = Assembly.LoadFrom(MakeLoadReadyAssemblyName(mappingAssembly)); m.HbmMappings.AddFromAssembly(assembly); m.FluentMappings.AddFromAssembly(assembly) .ConventionDiscovery.AddAssembly(assembly); } if (autoPersistenceModel != null) { m.AutoMappings.Add(autoPersistenceModel); } }); return(fluentConfiguration.BuildSessionFactory()); }
public static Configuration InitializeNHibernateSession() { string[] mappingAssemblies = GetMappingAssemblies(); AutoPersistenceModel autoPersistenceModel = GetAutoPersistenceModel(mappingAssemblies); return(NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies, autoPersistenceModel)); }
private static NHibernateOrg.ISessionFactory CreateSessionFactoryFor( IEnumerable <string> mappingAssemblies, AutoPersistenceModel autoPersistenceModel, Configuration cfg, IPersistenceConfigurer persistenceConfigurer) { var fluentConfiguration = Fluently.Configure(cfg); if (persistenceConfigurer != null) { fluentConfiguration.Database(persistenceConfigurer); } fluentConfiguration.Mappings( m => { foreach (var mappingAssembly in mappingAssemblies) { var assembly = Assembly.LoadFrom(MakeLoadReadyAssemblyName(mappingAssembly)); m.HbmMappings.AddFromAssembly(assembly); m.FluentMappings.AddFromAssembly(assembly).Conventions.AddAssembly(assembly); } if (autoPersistenceModel != null) { m.AutoMappings.Add(autoPersistenceModel); } }); fluentConfiguration.ExposeConfiguration(c => ConfigureValidator(c)); return(fluentConfiguration.BuildSessionFactory()); }
protected virtual AutoPersistenceModel GetAutoPersistenceModel(IAssemblyProvider assemblyProvider) { IEnumerable <Assembly> allLoadedAssemblies = assemblyProvider.GetAssemblies(); AutoPersistenceModel autoPersistenceModel = GetAutoPersistenceModel(allLoadedAssemblies); return(autoPersistenceModel); }
/// <summary> /// Alter the model /// </summary> /// <remarks> /// Finds all types in the assembly (passed in the constructor) that implement IAutoMappingOverride<T>, then /// creates an AutoMapping<T> and applies the override to it. /// </remarks> /// <param name="model">AutoPersistenceModel instance to alter</param> public void Alter(AutoPersistenceModel model) { // find all types deriving from IAutoMappingOverride<T> var types = from type in assembly.GetExportedTypes() let entity = (from interfaceType in type.GetInterfaces() where interfaceType.IsGenericType && interfaceType.GetGenericTypeDefinition() == typeof(IAutoMappingOverride <>) select interfaceType.GetGenericArguments()[0]).FirstOrDefault() where entity != null select new { OverrideType = type, EntityType = entity }; foreach (var typeMatch in types) { var mappingOverride = Activator.CreateInstance(typeMatch.OverrideType); var autoMapType = typeof(AutoMapping <>).MakeGenericType(typeMatch.EntityType); var mapping = (IMappingProvider)Activator.CreateInstance(autoMapType, new List <string>()); // HACK: call the Override method with the generic AutoMapping<T> var overrideMethod = typeMatch.OverrideType .GetMethod("Override"); GetType() .GetMethod("AddOverride", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(typeMatch.EntityType) .Invoke(this, new[] { model, typeMatch.EntityType, mappingOverride }); } }
protected virtual AutoPersistenceModel GetAutoPersistenceModel(IEnumerable <Assembly> allLoadedAssemblies) { IEnumerable <Type> allLoadedTypes = allLoadedAssemblies.SelectMany(assembly => assembly.GetTypes()); AutoPersistenceModel autoPersistenceModel = GetAutoPersistenceModel(allLoadedTypes, SessionAlias.Default); return(autoPersistenceModel); }
public static AutoPersistenceModel SagaPersistenceModel(IEnumerable <Type> typesToScan) { var sagaEntites = typesToScan.Where(t => typeof(ISagaEntity).IsAssignableFrom(t) && !t.IsInterface); var model = new AutoPersistenceModel(); model.Conventions.AddFromAssemblyOf <IdShouldBeAssignedConvention>(); var entityTypes = GetTypesThatShouldBeAutoMapped(sagaEntites, typesToScan); var assembliesContainingSagas = sagaEntites.Select(t => t.Assembly).Distinct(); foreach (var assembly in assembliesContainingSagas) { model.AddEntityAssembly(assembly) .Where(t => entityTypes.Contains(t)); } var componentTypes = GetTypesThatShouldBeMappedAsComponents(sagaEntites); model.Setup(s => { s.IsComponentType = type => componentTypes.Contains(type); }); return(model); }
private static ISessionFactory CreateSessionFactory(Assembly contextAssembly, IPersistenceConfigurer dbPersister, AutoPersistenceModel autoPersistanceModel = null) { // Create config var factoryConfig = Fluently.Configure(); factoryConfig.Database(dbPersister); return CreateSessionFactory(contextAssembly, factoryConfig, autoPersistanceModel); }
public static ISessionFactory GetSessionFactory(NhDataContext context, FluentConfiguration factoryConfig, AutoPersistenceModel autoPersistanceModel = null) { var contextType = context.GetType(); var contextAssembly = Assembly.GetAssembly(contextType); return _factories.GetOrAdd(contextType, CreateSessionFactory(contextAssembly, factoryConfig, autoPersistanceModel)); }
public static Configuration Init( ISessionStorage storage, string[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, IDictionary <string, string> cfgProperties) { return(Init(storage, mappingAssemblies, autoPersistenceModel, null, cfgProperties, null, null)); }
public static AutoPersistenceModel AddFilters(this AutoPersistenceModel model, IEnumerable <System.Type> types) { foreach (var type in types) { AddFilterMethodInfo.MakeGenericMethod(type).Invoke(model, null); } return(model); }
/// <summary>Generates a FluentConfiguration.</summary> /// <returns>The FluentConfiguration.</returns> public FluentConfiguration Generate() { Configuration config = CreateNHibernateConfiguration(); AutoPersistenceModel autoMapModel = this.autoMapGenerator.Generate(); FluentConfiguration fluentConfiguration = Fluently.Configure(config).Mappings(m => m.AutoMappings.Add(autoMapModel)); return(fluentConfiguration); }
private NHibernate.Cfg.Configuration InitializeNHibernateSession() { string[] mappingAssemblies = GetMappingAssemblies(); AutoPersistenceModel autoPersistenceModel = GetAutoPersistenceModel(mappingAssemblies); return(NHibernateSession.Init(new ThreadSessionStorage(), mappingAssemblies, autoPersistenceModel, "HibernateFile.cfg.xml")); }
public static Configuration Init( ISessionStorage storage, string[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, string cfgFile) { return(Init(storage, mappingAssemblies, autoPersistenceModel, cfgFile, null, null, null)); }
public static AutoPersistenceModel UseOverridesFromAssemblies(this AutoPersistenceModel model, IEnumerable <Assembly> assemblies) { foreach (var assembly in assemblies) { model.UseOverridesFromAssembly(assembly); } return(model); }
public static AutoPersistenceModel AddConventions(this AutoPersistenceModel model, IEnumerable <Assembly> assemblies) { foreach (var assembly in assemblies) { model.Conventions.AddAssembly(assembly); } return(model); }
public AutoPersistenceModel Generate() { var mappings = new AutoPersistenceModel(); mappings.AddEntityAssembly(typeof (Class1).Assembly).Where(GetAutoMappingFilter); mappings.Conventions.Setup(GetConventions()); mappings.Setup(GetSetup()); mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>(); return mappings; }
public static Configuration Init( ISessionStorage storage, string[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, string cfgFile, string validatorCfgFile) { return Init(storage, mappingAssemblies, autoPersistenceModel, cfgFile, null, validatorCfgFile, null); }
public static IMappingConfiguration CreateWithOverrides(AutoPersistenceModel autoPersistenceModel) { var configuration = Fluently.Configure() .Mappings(m => m.AutoMappings.Add(autoPersistenceModel)); return(new AutoMappingConfiguration { _fluentConfiguration = configuration }); }
private void Model <T>(Func <Member, bool> convention) { model = new PrivateAutoPersistenceModel() .Setup(conventions => conventions.FindMappablePrivateProperties = convention); model.AddTypeSource(new StubTypeSource(typeof(T))); model.CompileMappings(); model.BuildMappings(); }
private static ISessionFactory BuildSessionFactory() { AutoPersistenceModel model = CreateMappings(); return(Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(ConfigurationManager.ConnectionStrings["OakTestsConnectionString"].ConnectionString)) .Mappings(m => m.AutoMappings.Add(model)) .BuildSessionFactory()); }
public static AutoPersistenceModel IncludeAppConventions(this AutoPersistenceModel model) { foreach (var baseType in TypeHelper.GetAllConcreteTypesAssignableFrom <MrCMSApp>() .Select(type => Activator.CreateInstance(type) as MrCMSApp) .SelectMany(app => app.Conventions)) { model.Conventions.Add(baseType); } return(model); }
public AutoPersistenceModel Generate() { var mappings = new AutoPersistenceModel(); mappings.AddEntityAssembly(typeof(Site).Assembly).Where(GetAutoMappingFilter); // mappings.Setup(GetSetup()); mappings.IgnoreBase<Entity>(); mappings.IgnoreBase(typeof(EntityWithTypedId<>)); mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>(); return mappings; }
public static AutoPersistenceModel UseConventionsFromAssemblies(this AutoPersistenceModel model, params Assembly[] assemblies) { foreach ( Assembly assembly in assemblies.Where(assembly => !assembly.IsDynamic && !assembly.GlobalAssemblyCache)) { model.Conventions.AddAssembly(assembly); } return(model); }
private AutoPersistenceModel Generate() { AutoPersistenceModel mappings = AutoMap.Assemblies( new AutoMapConfiguration(), new Assembly[] { this.GetType().Assembly }); mappings.UseOverridesFromAssembly(this.GetType().Assembly); return(mappings); }
private void VerifyMapping(AutoPersistenceModel model, Action<CompositeIdMapping> verifier) { var idMapping = model.BuildMappings() .First() .Classes .First() .Id ; idMapping.ShouldBeOfType(typeof(CompositeIdMapping)); verifier((CompositeIdMapping)idMapping); }
public Configuration Generate() { var model = new AutoPersistenceModel() .AddEntityAssembly(Assembly.GetExecutingAssembly()) .Where(x => x.Namespace.IsNotNullOrEmpty() && x.Namespace.StartsWith("FakeVader.Core.Domain")) .Conventions.AddFromAssemblyOf<HasManyConvention>(); return Fluently.Configure() .Database(databaseConfig) .Mappings( configuration => configuration.AutoMappings.Add(model) ).BuildConfiguration(); }
public AutoPersistenceModel Generate() { var mappings = new AutoPersistenceModel(); mappings.AddEntityAssembly(typeof (Class1).Assembly).Where(GetAutoMappingFilter); mappings.Conventions.Setup(GetConventions()); mappings.Setup(GetSetup()); mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>(); mappings.Override<Idea>(i => i.Map(m => m.Text).CustomSqlType("TEXT")); mappings.Override<Comment>(c => c.Map(m => m.Text).CustomSqlType("TEXT")); return mappings; }
public AutoPersistenceModel Generate() { var mappings = new AutoPersistenceModel(); mappings .AddEntityAssembly(typeof(Player).Assembly) .UseOverridesFromAssembly(typeof(AutoPersistenceModelGenerator).Assembly) .Where(GetAutoMappingFilter); //.Setup(GetSetup()) //.Conventions.Setup(GetConventions); MapEnums(mappings); return mappings; }
public void Alter(AutoPersistenceModel model) { // if any type has a property of this type // that is of a type (or has a collection of a type) // that is abstract // is not generic // and inherits from entity // and has inheritors in the domain // then include that type // foreach property in type foreach (var strategyType in Strategies()) { model.IncludeBase(strategyType); } }
/// <summary> /// Alter the model /// </summary> /// <remarks> /// Finds all types in the assembly (passed in the constructor) that implement IAutoMappingOverride<T>, then /// creates an AutoMapping<T> and applies the override to it. /// </remarks> /// <param name="model">AutoPersistenceModel instance to alter</param> public void Alter(AutoPersistenceModel model) { // find all types deriving from IAutoMappingOverride<T> var types = from type in assembly.GetExportedTypes() where !type.IsAbstract let entity = (from interfaceType in type.GetInterfaces() where interfaceType.IsGenericType && interfaceType.GetGenericTypeDefinition() == typeof(IAutoMappingOverride<>) select interfaceType.GetGenericArguments()[0]).FirstOrDefault() where entity != null select type; foreach (var type in types) { model.Override(type); } }
public virtual void fup() { domainModel = new AutoPersistenceModel(new AutoMapConfig()) .AddEntityAssembly(Assembly.GetAssembly(typeof(IEntity))) .UseOverridesFromAssemblyOf<AirplayAutoMap>(); var dbConfig = SQLiteConfiguration.Standard.UsingFile("gema4").ShowSql(); //var dbConfig = SQLiteConfiguration.Standard.UsingFile("gema4"); cfg = Fluently.Configure() .Mappings(m => m.AutoMappings.Add(domainModel)) .Database(dbConfig) .BuildConfiguration(); sf = cfg.BuildSessionFactory(); }
public AutoPersistenceModel Generate() { var mappings = new AutoPersistenceModel(); mappings = AutoMap.AssemblyOf<Domain.Entity>(); mappings.Where(GetAutoMappingFilter); mappings.Conventions.Setup(GetConventions()); mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>(); mappings.Setup(GetSetup()); mappings.OverrideAll(x => x.IgnoreProperties(z => z.PropertyType.IsSubclassOf(typeof(Enumeration)))); mappings.IgnoreBase<Domain.Entity>(); mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>(); return mappings; }
static ISessionFactory create() { var domainModel = new AutoPersistenceModel(new AutoMapConfig()) .AddEntityAssembly(Assembly.GetAssembly(typeof(IEntity))) .UseOverridesFromAssemblyOf<AirplayAutoMap>(); var sqlite = SQLiteConfiguration.Standard .ConnectionString(x => x.Is("Data Source=|DataDirectory|gema4")) .CurrentSessionContext("web"); var _sf = Fluently.Configure() .Mappings(m => m.AutoMappings.Add(domainModel)) .Database(sqlite) .BuildSessionFactory(); return _sf; }
public ISessionFactory GetSessionFactory(string connection) { var model = new AutoPersistenceModel() .AddEntityAssembly(typeof(Product).Assembly) .Where(t => t.Namespace.StartsWith(typeof(Product).Namespace)) .Conventions.AddFromAssemblyOf<TableNameConvention>() .UseOverridesFromAssemblyOf<CartMapOverride>(); ISessionFactory fluentConfiguration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2012 .ConnectionString(c => c.FromConnectionStringWithKey(connection)) .ShowSql()) .Mappings(m => m.AutoMappings.Add(model)) .BuildSessionFactory(); return fluentConfiguration; }
public NHibernatePersistenceModel() { _autoPersistenceModel = AutoPersistenceModel .MapEntitiesFromAssemblyOf<DomainEntity>() .WithAlterations(x => x.Add<AutoMappingAlteration>()) .WithSetup(s => { s.FindIdentity = type => type.Name == "ID"; s.IsBaseType = type => type == typeof (DomainEntity); }) //.Where(type => // typeof (DomainEntity).IsAssignableFrom(type) && // type.Namespace == "Fohjin.Core.Domain") .ConventionDiscovery .AddFromAssemblyOf<IdentityColumnConvention>() .UseOverridesFromAssemblyOf<UserMappingOverride>(); }
public AutoPersistenceModel BuildPersistenceModel() { var persistenceModel = new AutoPersistenceModel(); persistenceModel.Conventions.Setup(c => { c.Add(typeof(ForeignKeyNameConvention)); c.Add(typeof(ReferenceConvention)); c.Add(typeof(PrimaryKeyNameConvention)); c.Add(typeof(TableNameConvention)); }); persistenceModel.AddMappingsFromAssembly(AssemblyMapper); persistenceModel.WriteMappingsTo(@"./"); return persistenceModel; }
private static AutoPersistenceModel GetAutoMappingSettings( Assembly entitiesAssembly, Assembly mappingsOverridesAssembly ) { var persistenceModel = new AutoPersistenceModel(); persistenceModel.AddEntityAssembly( entitiesAssembly ).Where( x => x.BaseType.Name == "BaseEntity" ); persistenceModel.UseOverridesFromAssembly( mappingsOverridesAssembly ); persistenceModel.Conventions.Add( PrimaryKey.Name.Is( x => "Id" ), ConventionBuilder.Id.Always( x => x.GeneratedBy.Identity() ), ConventionBuilder.Property.Always( x => x.Not.Nullable() ), ConventionBuilder.Property.When( expectation => expectation.Expect( propertyInspector => propertyInspector.Property.PropertyType == typeof( string ) ), instance => instance.Length( 256 ) ), ConventionBuilder.Reference.Always( x => x.Not.Nullable() ), ForeignKey.EndsWith( "Id" ) ); return persistenceModel; }
public AutoPersistenceModel Generate() { var mappings = new AutoPersistenceModel(); mappings.AddEntityAssembly(typeof(Soul).Assembly).Where(GetAutoMappingFilter); mappings.Conventions.Setup(GetConventions()); mappings.Setup(GetSetup()); mappings.IgnoreBase<Entity>(); mappings.IgnoreBase(typeof(EntityWithTypedId<>)); mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>(); // Membershipprovider Automappings mappings.AddEntityAssembly(typeof(Shaml.Membership.Core.User).Assembly).Where(GetAutoMappingFilter); mappings.Override<Shaml.Membership.Core.User>(map => Shaml.Membership.Data.Overrides.UserOverride(map)); mappings.Override<Shaml.Membership.Core.Role>(map => Shaml.Membership.Data.Overrides.RoleOverride(map)); mappings.Override<Shaml.Membership.Core.ProfileData>(map => Shaml.Membership.Data.Overrides.ProfileDataOverride(map)); mappings.Override<Shaml.Membership.Core.Session>(map => Shaml.Membership.Data.Overrides.SessionOverride(map)); return mappings; }
ISessionFactory GetSessionFactory() { var autoPersistenceModel = new AutoPersistenceModel(); autoPersistenceModel .AddEntityAssembly(GetType().Assembly) .Where(t => t.Namespace.StartsWith("NHibernateWebPersistenceExample.Models")); ISessionFactory sessionFactory = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008 .ConnectionString(c => c.Is( @"Data Source=.\SQLEXPRESS;Initial Catalog=Example;Integrated Security=True;Pooling=False")) .ShowSql()) .Mappings(m => m.AutoMappings.Add(autoPersistenceModel)) .ExposeConfiguration(innerConfiguration => innerConfiguration.SetProperty("current_session_context_class", "web")) .BuildSessionFactory(); return sessionFactory; }
private static ISessionFactory CreateSessionFactory(Assembly contextAssembly, FluentConfiguration factoryConfig, AutoPersistenceModel autoPersistanceModel = null) { // Create mapping config factoryConfig.Mappings(m => { m.HbmMappings.AddFromAssembly(contextAssembly); m.FluentMappings.AddFromAssembly(contextAssembly); if (autoPersistanceModel != null) { m.AutoMappings.Add(autoPersistanceModel); } }); // Exemple of schemaExport and create // factoryConfig.ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true)); // Create factory var sessionFactory = factoryConfig.BuildSessionFactory(); return sessionFactory; }
public AutoPersistenceModel Generate() { //todo: add conventions etc. var autoPersistanceModel = new AutoPersistenceModel() .AddEntityAssembly(Assembly.GetAssembly(typeof(User))) .Where(GetAutoMappingFilter) .Conventions.Add( //PrimaryKey.Name.Is(x=> PrimaryKey.Name+"Id") ) .UseOverridesFromAssemblyOf<UserMap>(); return autoPersistanceModel; //var mappings = AutoPersistenceModel // .MapEntitiesFromAssemblyOf<>() // .ForTypesThatDeriveFrom<User>(map => map.Map(u => u.Username).SetAttribute("unique-key", "IX_Unique_UserName")) // .ForTypesThatDeriveFrom<Ingredient>(map => map.Map(i => i.Name).SetAttribute("unique-key", "IX_Unique_IngredientName")) // .Where(GetAutoMappingFilter) // .WithConvention(GetConventions) // .UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>(); //return mappings; }
private static void InternalRegisterPersistence(ContainerBuilder builder, string connectionString, AutoPersistenceModel autoPersistenceModel) { builder.RegisterType<PersistenceModelAuditor>().AsSelf(); builder.RegisterType<TransactionManagingInterceptor>().AsSelf(); builder.Register(cx => RegisterConfiguration(cx, connectionString, autoPersistenceModel)) .As<Configuration>().SingleInstance(); builder.Register(cx => { var configuration = cx.Resolve<Configuration>(); var sessionFactory = configuration.BuildSessionFactory(); return sessionFactory; }).As<ISessionFactory>().SingleInstance(); builder.Register(cx => { var sessionFactory = cx.Resolve<ISessionFactory>(); var session = sessionFactory.OpenSession(); session.EnableFilter(SoftDeletableFilter.FilterName); return session; }).As<ISession>().InstancePerLifetimeScope(); }
/// <summary> /// Configures FluentNHibernate to map the domain types used in PerfTest. /// </summary> public static AutoPersistenceModel AutoMap(AutoPersistenceModel model) { model .AddEntityAssembly(typeof(TestSuiteResult).Assembly) .Override<TestSuiteResult>(map => { map.HasMany(x => x.SystemInfoList).AsSet().Inverse().Cascade.All().Not.LazyLoad(); map.HasMany(x => x.TestResultList).AsSet().Inverse().Cascade.All().Not.LazyLoad(); }) .Override<SystemInfo>(map => { map.References(x => x.TestSuiteResult, "TestSuiteResultId").Cascade.None().Not.Nullable(); }) .Override<TestResult>(map => { map.HasMany(x => x.TimingDataList).AsSet().Inverse().Cascade.All().Not.LazyLoad(); map.References(x => x.TestSuiteResult, "TestSuiteResultID").Cascade.None().Not.Nullable(); }) .Override<TimingData>(map => { map.References(x => x.TestResult, "TestResultID").Cascade.None().Not.Nullable(); }); return model; }
public void Alter(AutoPersistenceModel model) { }
public override void Map(IDomainDefinition domain, AutoPersistenceModel model) { base.Map(domain, model); }
public override void Map(IDomainDefinition domain, AutoPersistenceModel model) { base.Map(domain, model); model.Add(new VersionFilter()); }