예제 #1
0
 public void OptimisticLockShouldntOverrideDirectSetting()
 {
     new MappingTester <MappedObject>()
     .Conventions(conventions => conventions.Add(OptimisticLock.Is(x => x.All())))
     .ForMapping(c => c.OptimisticLock.Dirty())
     .Element("class").HasAttribute("optimistic-lock", "dirty");
 }
예제 #2
0
 public void OptimisticLockShouldSetAttributeIfSupplied()
 {
     new MappingTester <MappedObject>()
     .Conventions(conventions => conventions.Add(OptimisticLock.Is(x => x.All())))
     .ForMapping(c => { })
     .Element("class").HasAttribute("optimistic-lock", "all");
 }
예제 #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            var persistenceModel = AutoMap.Assemblies(
                new AutoMappingConfiguration(),
                Enumerable.Empty <Assembly>());

            persistenceModel
            .Conventions.AddAssembly(Assembly.GetExecutingAssembly())
            .Conventions.Add(
                ConventionBuilder.Id.Always(x => x.Column("Id")),
                ForeignKey.EndsWith("Id"),
                ConventionBuilder.Property.When(
                    x => x.Expect(y => y.ReadOnly),
                    x => x.Access.CamelCaseField(FluentNHibernate.Conventions.Inspections.CamelCasePrefix.Underscore)
                    ),
                DynamicInsert.AlwaysTrue(),
                DynamicUpdate.AlwaysTrue(),
                OptimisticLock.Is(x => x.Version()))
            .UseOverridesFromAssemblyOf <Startup>()
            .AddEntityAssembly(typeof(Startup).Assembly)
            .AddMappingsFromAssemblyOf <Startup>();

            var sessionFactory = Fluently.Configure()
                                 .Database(MsSqlConfiguration.MsSql2008.ConnectionString(this.Configuration.GetConnectionString("Default")))
                                 .ExposeConfiguration(config =>
            {
                config.SetInterceptor(new AbpNHibernateInterceptor());
                new SchemaValidator(config).Validate();
            })
                                 .Mappings(
                m =>
            {
                m.AutoMappings.Add(persistenceModel);
            })
                                 .BuildSessionFactory();

            services.AddSingleton <ISessionFactory>(sessionFactory);
        }
예제 #4
0
        private ISessionFactory CreateSessionFactory()
        {
            var connectionString = Configuration.GetSection("NhibernateConfig").Get <NhibernateConfig>().ConnectionString;
            //var dbCfg = OracleManagedDataClientConfiguration.Oracle10.Dialect<Oracle12cDialect>().ConnectionString(db => db.Is(connectionString));
            var dbCfg = PostgreSQLConfiguration.Standard.Dialect <PostgreSQL83Dialect>().ConnectionString(db => db.Is(connectionString));

            return(Fluently.Configure()
                   .Database(dbCfg)
                   .Cache(cfg => cfg.Not.UseSecondLevelCache())
                   .Mappings(cfg =>
                             cfg.FluentMappings.AddFromAssemblyOf <DbContext>()
                             .Conventions
                             .Add(
                                 ConventionBuilder.HasManyToMany.When(
                                     c => c.Expect(p => p.TableName, Is.Not.Set),                     // when this is true
                                     c => c.Table(string.Concat(c.EntityType.Name, c.ChildType.Name)) // do this
                                     ),
                                 OptimisticLock.Is(x => x.Version())))
                   .ExposeConfiguration(cfg =>
            {
#if DEBUG
                cfg.DataBaseIntegration(db =>
                {
                    db.LogFormattedSql = true;
                    db.LogSqlInConsole = true;
                });
#endif
                cfg.SetProperty(Environment.BatchSize, "100");
                cfg.SetProperty(Environment.DefaultBatchFetchSize, "20");
                cfg.SetProperty(Environment.OrderInserts, "true");
                cfg.SetProperty(Environment.OrderUpdates, "true");
                cfg.SetProperty(Environment.BatchVersionedData, "true");
                BuildSchema(cfg);       //<-- uncomment this to create DB schema
            })
                   .BuildSessionFactory());
        }