private static IEnumerable <IConvention> GetConventions() { yield return(Table.Is(x => x.EntityType.Name)); // TODO: TBD: does not seem to be taking? having to specify Id column? yield return(Id.Always(x => x.Column("Id"))); yield return(HasMany.Always(x => x.Cascade.AllDeleteOrphan())); yield return(HasMany.Always(x => x.LazyLoad())); yield return(HasMany.Always(x => x.Inverse())); yield return(HasMany.Always(x => x.AsBag())); yield return(Reference.Always(x => x.LazyLoad())); yield return(Reference.Always(x => x.Cascade.All())); //// TODO: TBD: not strong enough: //yield return ForeignKey.EndsWith("Id"); // TODO: TBD: does not seem to be taking? having to specify each reference column name? yield return(ForeignKey.Format((p, t) => (p == null ? t.Name : p.Name) + "Id")); // TODO: ditto Id Alwyas Id? yield return(PrimaryKey.Name.Is(x => "Id")); yield return(DefaultCascade.All()); yield return(DefaultLazy.Always()); }
public void ShouldSetDefaultAccessToValue() { model.Add(new ClassMap <Target>()); model.Conventions.Add(DefaultCascade.All()); model.BuildMappings() .First() .DefaultCascade.ShouldEqual("all"); }
private static void ConfigureConventions(IConventionFinder conventions) { conventions.Add(DefaultCascade.All()); conventions.Add(DefaultLazy.Always()); conventions.Add(ConventionBuilder.Id.Always(convention => convention.GeneratedBy.GuidComb())); conventions.Add(ConventionBuilder.HasMany.Always(convention => convention.Inverse())); conventions.Add(ConventionBuilder.HasMany.Always(convention => convention.Cascade.AllDeleteOrphan())); }
static AutoPersistenceModel CreateAutomappings() { return(AutoMap.AssemblyOf <T>() .Where(type => type.Namespace == "Domaine") .Conventions.Add( DefaultCascade.All(), DefaultLazy.Always() )); }
static void SetupTestMappings(FluentConfiguration config) { config.Mappings(map => map.AutoMappings.Add(AutoMap.AssemblyOf <BaseTest>() .Where(typ => typ.Namespace.EndsWith("TestEntities")) .Conventions.Add(DefaultCascade.All()) .SupportNullablePrimaryKeysNativeGenerated() .UseOverridesFromAssemblyOf <NullablePrimaryKeyConvention>())); }
public void AlwaysShouldSetDefaultLazyToTrue() { model.Add(new ClassMap <Target>()); model.Conventions.Add(DefaultLazy.Always()); model.Conventions.Add(DefaultCascade.All()); var mapping = model.BuildMappings().First(); mapping.DefaultLazy.ShouldBeTrue(); mapping.DefaultCascade.ShouldEqual("all"); }
public static AutoPersistenceModel GetNhibernateServicesMappings(bool registerOperationalServices, bool registerConfigurationServices) { var config = new AutomappingConfiguration(registerOperationalServices, registerConfigurationServices); var map = AutoMap.AssemblyOf <IBaseEntity>(config) .Conventions.Add(DefaultCascade.All()) .UseOverridesFromAssemblyOf <IBaseEntity>() .IgnoreBase(typeof(BaseEntity <>)); return(map); }
private static FluentConfiguration FluentConfig() { var settings = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("settings.json") .AddEnvironmentVariables().Build(); var settingsToUse = settings["DatabaseToUse"]; var context = settings["SessionContext"]; var connectionStringFormatter = "ConnectionStrings:{0}:ConnectionString"; var providerFormatter = "ConnectionStrings:{0}:Provider"; var driverFormatter = "ConnectionStrings:{0}:Driver"; var connectionString = settings[string.Format(connectionStringFormatter, settingsToUse)]; var providerString = settings[string.Format(providerFormatter, settingsToUse)]; var driverString = settings[string.Format(driverFormatter, settingsToUse)]; var storeConfig = new StoreConfiguration(); //var hbmExport = @"C:\Users\jody_unterschutz\source\repos\TeamApp\TeamApp.Test.Database\HBM Files\"; use this if we want to export hbm xml files //we need to remap all of the classes explicitly. //https://github.com/FluentNHibernate/fluent-nhibernate/wiki return(Fluently.Configure() .Database(MsSqlConfiguration.MsSql2012 .ConnectionString(connectionString) .Provider(providerString) .Driver(driverString) //.ShowSql() ) .CurrentSessionContext("thread_static") .Mappings(m => { m.FluentMappings.AddFromNamespaceOf <LeagueMap>().Conventions.Add(DefaultCascade.All()); /* * m.AutoMappings.Add( * AutoMap.AssemblyOf<Team>(storeConfig) * .IgnoreBase<BaseDataObject>() * .IncludeBase<CompetitionConfig>() * .IncludeBase<PlayoffSeries>() * .IncludeBase<Competition>() * .IncludeBase<CompetitionConfigFinalRankingRule>() * .Conventions.Add(DefaultCascade.All()) * ); */ }) .ExposeConfiguration(c => c.EventListeners.PreUpdateEventListeners = new IPreUpdateEventListener[] { new AuditEventListener() }) .ExposeConfiguration(c => c.EventListeners.PreInsertEventListeners = new IPreInsertEventListener[] { new AuditEventListener() })); }
public StockNhContextModelUpdate(string connectionString) { SessionFactory = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2012 .ConnectionString(connectionString).ShowSql()) .Mappings(m => m.FluentMappings .Add <CompanyNhibernateMap>().Conventions.Add(DefaultCascade.All()) .Add <StockQuoteNhibernateMap>().Conventions.Add(DefaultCascade.All()) ) .ExposeConfiguration(cfg => SchemaMetadataUpdater.QuoteTableAndColumns(cfg, new MsSql2012Dialect())) .ExposeConfiguration(cfg => new SchemaExport(cfg).Execute(true, true, false)) .BuildSessionFactory(); }
private static Action <MappingConfiguration> MappingConfig() { var domainAssembly = Assembly.GetAssembly(typeof(Person)); return(m => m .AutoMappings .Add(AutoMap .Assembly(domainAssembly, new DomainMappingConfiguration()) .UseOverridesFromAssembly(domainAssembly) .Conventions.Setup(c => { c.Add(DefaultCascade.All()); c.Add <CustomForeignKeyConvention>(); c.Add <DefaultStringLengthConvention>(); c.Add <EnumConvention>(); c.Add <DateTimeConvention>(); })) .ExportTo(HostingEnvironment.MapPath("~/App_Data/Mappings/"))); }
public ISessionFactory CreateSessionFactory() { return(Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008 .ConnectionString(_configurationService.ConnectionString) .AdoNetBatchSize(20) .ShowSql()) .Mappings(m => m. AutoMappings.Add( AutoMap.AssemblyOf <PersistentObject>() .Where(type => type.IsSubclassOf(typeof(PersistentObject))) .Conventions.Add( Table.Is(x => Inflector.Net.Inflector.Pluralize(x.EntityType.Name)), PrimaryKey.Name.Is(x => "ID"), ForeignKey.EndsWith("ID"), ConventionBuilder.Class.Always(x => x. Schema(x.EntityType.Namespace == null || x.EntityType.Namespace.EndsWith("Domain") ? "dbo" : x.EntityType.Namespace.Substring(x.EntityType.Namespace.LastIndexOf(".")))), DefaultCascade.All() ))) .ExposeConfiguration(x => DbConfiguration = x) .BuildSessionFactory()); }
public ISessionFactory CreateSessionFactory() { return(Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008 .ConnectionString(_configurationService.ConnectionString) .AdoNetBatchSize(20) .ShowSql()) .Mappings(m => m.AutoMappings.Add( AutoMap.AssemblyOf <NHibernateRepository>(new MyAutoConfig()) .UseOverridesFromAssemblyOf <NHibernateRepository>() .Conventions.Add( Table.Is(x => Inflector.Net.Inflector.Pluralize(x.EntityType.Name)), PrimaryKey.Name.Is(x => "ID"), ForeignKey.EndsWith("ID"), ConventionBuilder.HasManyToMany.Always(x => x.AsList()), DefaultCascade.All(), ConventionBuilder.Class.Always(x => x.Schema( x.EntityType.Namespace == null || x.EntityType.Namespace.EndsWith("Domain") ? "dbo" : x.EntityType.Namespace.Substring(x.EntityType.Namespace.LastIndexOf("."))))))) .ExposeConfiguration(cfg => Configuration = cfg) .BuildSessionFactory()); }
public void Accept(IAcceptanceCriteria <IManyToManyCollectionInspector> criteria) { DefaultCascade.All(); }
public void Apply(IManyToOneInstance instance) { DefaultCascade.All(); }
public void Apply(IOneToManyCollectionInstance instance) { DefaultCascade.All(); }