예제 #1
0
 public TokenMap()
 {
     DefaultLazy.Always();
     Id(x => x.Id);//, map => map.Generator(Generators.Assigned));
     Map(x => x.UserId);
     Map(x => x.AuthToken);
     Map(x => x.IssuedOn);
     Map(x => x.ExpiresOn);
     //References(c => c.UserId, "UserId");
 }
예제 #2
0
        public void Apply(MappingConfiguration configuration)
        {
            var conventions = configuration.FluentMappings.Conventions;

            //conventions.Add(ConventionBuilder
            //                    .Class.Always(
            //                        x => x.Table(Inflector.Net.Inflector.Pluralize(x.EntityType.Name).Escape())));
            conventions.Add(ConventionBuilder.Property.Always(x => x.Column(x.Property.Name)));
            conventions.Add(DefaultLazy.Always());
        }
        public void AlwaysShouldSetDefaultLazyToTrue()
        {
            var classMap = new ClassMap <Target>();

            classMap.Id(x => x.Id);
            model.Add(classMap);
            model.Conventions.Add(DefaultLazy.Always());
            model.BuildMappings()
            .First()
            .DefaultLazy.ShouldBeTrue();
        }
예제 #4
0
 public FedTaxTableMap()
 {
     DefaultLazy.Always();
     Id(x => x.Id);                             //, map => map.Generator(Generators.Assigned));
     Map(x => x.Year).Not.Nullable();           //, map => map.NotNullable(true));
     Map(x => x.Payfrequency).Not.Nullable();   //, map => map.NotNullable(true));
     Map(x => x.Maritalsatus).Not.Nullable();   //, map => map.NotNullable(true));
     Map(x => x.Over).Not.Nullable();           //, map => map.NotNullable(true));
     Map(x => x.Withhold).Not.Nullable();       //, map => map.NotNullable(true));
     Map(x => x.Pluspercentage).Not.Nullable(); //, map => map.NotNullable(true));
 }
예제 #5
0
 public EmailMap()
 {
     DefaultLazy.Always();
     Id(x => x.Id);                    //, map => map.Generator(Generators.Assigned));
     Map(x => x.Type).Not.Nullable();; //, map => map.NotNullable(true));
     Map(x => x.Isprimary);
     Map(x => x.Name);
     Map(x => x.Domain);
     Map(x => x.Notes);
     //ManyToOne(x => x.Employees, map => { map.Column("employeeID"); map.Cascade(Cascade.None); });
 }
        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");
        }
예제 #7
0
 public EmployeeDeductionMap()
 {
     DefaultLazy.Always();
     Id(x => x.Id);                        //, map => map.Generator(Generators.Assigned));
     Map(x => x.Description);
     Map(x => x.Frequency).Not.Nullable(); //, map => map.NotNullable(true));
     Map(x => x.Skip).Not.Nullable();      //, map => map.NotNullable(true));
     Map(x => x.Amountflag);
     Map(x => x.Amount);
     Map(x => x.Annuallimit);
     //ManyToOne(x => x.Employees, map => { map.Column("employeeID"); map.Cascade(Cascade.None); });
 }
예제 #8
0
        private void ConfigureMappings(MappingConfiguration config)
        {
            Database.Configuration.Mappings.ForEach(map => config.FluentMappings.AddFromAssembly(map));

            config.FluentMappings.Conventions.Add <EnumConvention>();
            config.FluentMappings.Conventions.Add <MonthConvention>();

            config.FluentMappings.Conventions.Add(
                DefaultLazy.Always(),
                DefaultCascade.None(),
                DynamicInsert.AlwaysTrue(),
                DynamicUpdate.AlwaysTrue());
        }
예제 #9
0
 private static Action <FluentNHibernate.Conventions.IConventionFinder> GetConventions()
 {
     return(mappings =>
     {
         mappings.Add <PrimaryKeyConvention>();
         mappings.Add <TableNameConvention>();
         mappings.Add <EnumConvention>();
         mappings.Add(ForeignKey.EndsWith("Id"));
         mappings.Add(DefaultCascade.None());
         mappings.Add(DefaultAccess.Property());
         mappings.Add(DefaultLazy.Always());
         mappings.Add(LazyLoad.Always());
     });
 }
예제 #10
0
 public UserMap()
 {
     DefaultLazy.Always();
     Id(x => x.Id);
     Map(x => x.UserName).Not.Nullable();
     Map(x => x.Password).Not.Nullable();
     Map(x => x.Locked);
     Map(x => x.SessionId);
     Map(x => x.SessionStart);
     Map(x => x.SessionEnd);
     Map(x => x.Roles);
     References(c => c.Payor, "payorId");
     //ManyToOne(x => x.Payors, map => { map.Column("payorID"); map.Cascade(Cascade.None); });
 }
예제 #11
0
        public TimepuncheMap()
        {
            DefaultLazy.Always();
            Id(x => x.Id);//, map => map.Generator(Generators.Assigned));
            Map(x => x.Indatetime);
            Map(x => x.Outdatetime);
            Map(x => x.Referencedate);
            Map(x => x.Hours);
            Map(x => x.Hourlypayrate);
            Map(x => x.Dailyrate);
            Map(x => x.Processed);

            //TODO
            //Map(x => x.Employees, map => { map.Column("employeeID"); map.Cascade(Cascade.None); });
        }
예제 #12
0
 public EmployeechangelogMap()
 {
     DefaultLazy.Always();
     Id(x => x.Id);//, map => map.Generator(Generators.Assigned));
     Map(x => x.Changedate);
     Map(x => x.From);
     Map(x => x.To);
     Map(x => x.Userid);
     //ManyToOne(x => x.Employees, map =>
     //{
     //	map.Column("employeeID");
     //	map.NotNullable(true);
     //	map.Cascade(Cascade.None);
     //});
 }
예제 #13
0
 public AddressMap()
 {
     DefaultLazy.Always();
     Id(x => x.Id);
     Map(x => x.Type).Not.Nullable();
     Map(x => x.Isprimary).Not.Nullable();
     Map(x => x.Line1);
     Map(x => x.Line2);
     Map(x => x.Line3);
     Map(x => x.City);
     Map(x => x.State);
     Map(x => x.Zip);
     Map(x => x.Notes);
     References(c => c.Employees, "employeeID");
     //ManyToOne(x => x.Employees, map => { map.Column("employeeID"); map.Cascade(Cascade.None); });
 }
예제 #14
0
        public CheckMap()
        {
            DefaultLazy.Always();
            Id(x => x.Id);//, map => map.Generator(Generators.Assigned));
            Map(x => x.Employeeid);
            Map(x => x.Amount);
            Map(x => x.Checknumber);
            Map(x => x.Checkdate);
            Map(x => x.Banknumber);
            Map(x => x.Accountnumber);
            Map(x => x.Lastname);
            Map(x => x.Firstname);
            Map(x => x.Voidflag);

            //ManyToOne(x => x.Payperiods, map => { map.Column("payPeriodID"); map.Cascade(Cascade.None); });
        }
예제 #15
0
 public PayperiodMap()
 {
     DefaultLazy.Always();
     Id(x => x.Id);//, map => map.Generator(Generators.Assigned));
     Map(x => x.Payfrequency);
     Map(x => x.Enddate);
     Map(x => x.Startdate);
     Map(x => x.Checkdate);
     Map(x => x.Tansferdate);
     Map(x => x.Status);
     Map(x => x.Runcount);
     Map(x => x.Inprogress);
     //ManyToOne(x => x.Payors, map =>
     //{
     //	map.Column("payorID");
     //	map.NotNullable(true);
     //	map.Cascade(Cascade.None);
     //});
 }
예제 #16
0
 public EarningMap()
 {
     DefaultLazy.Always();
     Id(x => x.Id).Not.Nullable();//, map => map.Generator(Generators.Assigned));
     Map(x => x.Employeeid);
     Map(x => x.Referencedate);
     Map(x => x.Hours);
     Map(x => x.Hourlypayrate);
     Map(x => x.Overtimemultiplier);
     Map(x => x.Amount);
     Map(x => x.Holiday);
     Map(x => x.Closedflag);
     Map(x => x.Fromtimepunches);
     Map(x => x.Payperiodid);
     //ManyToOne(x => x.Checks, map =>
     //{
     //	map.Column("checkID");
     //	map.NotNullable(true);
     //	map.Cascade(Cascade.None);
     //});
 }
예제 #17
0
        ISessionFactory InitializeSessionFactory()
        {
            var conventions = new IConvention[]
            {
                Table.Is(x => x.EntityType.Name.ToLowerInvariant()), // All table names are lower case
                ForeignKey.EndsWith("Id"),                           // Foreign key references end with Id
                DefaultLazy.Always()                                 // Enable Lazy-Loading by default
            }
            .Concat(DatabaseConventions.NeverNull())
            .ToArray();

            var config = Fluently.Configure()
                         .Database(DatabaseConfiguration)
                         .Mappings(m => m.FluentMappings
                                   .AddFromAssemblyOf <DatabaseAdapter>()
                                   .Conventions.Add(conventions));

            nhConfig       = config.BuildConfiguration();
            sessionFactory = config.BuildSessionFactory();

            return(sessionFactory);
        }
예제 #18
0
        public DatabaseFixture()
        {
            var databaseFileName = $"InstaLikeTestDb-{Guid.NewGuid()}.sqlite";

            SessionFactory = Fluently.Configure()
                             .Database(
                SQLiteConfiguration.Standard
                .ConnectionString(BuildTestDatabaseConnectionString(databaseFileName))
                .AdoNetBatchSize(20)
                .ShowSql()
                .FormatSql()
                .UseReflectionOptimizer()
                )
                             .Mappings(m =>
                                       m.FluentMappings
                                       .Conventions.Add(
                                           DefaultLazy.Always(),
                                           DynamicInsert.AlwaysTrue(),
                                           DynamicUpdate.AlwaysTrue(),
                                           new AssociationsMappingConvention(),
                                           new DateTimeOffsetTypeConvention()
                                           )
                                       .Add <UserMapping>()
                                       .Add <FollowMapping>()
                                       .Add <PostMapping>()
                                       .Add <CommentMapping>()
                                       .Add <LikeMapping>()
                                       .Add <NotificationMapping>()
                                       )
                             .ExposeConfiguration(async cfg =>
            {
                var schemaExport = new SchemaExport(cfg);
                schemaExport.SetOutputFile($"{databaseFileName}_Schema.sql");
                await schemaExport.DropAsync(true, true);
                await schemaExport.CreateAsync(true, true);
            })
                             .BuildSessionFactory();
        }
예제 #19
0
        public EmployeeMap()
        {
            DefaultLazy.Always();

            //this.ApplyFilter()

            Id(x => x.Id);                                  //, map => map.Generator(Generators.Assigned));
            Map(x => x.Number);
            Map(x => x.IsDeleted, "active").Not.Nullable(); //, map => map.NotNullable(true));
            Map(x => x.Socsec).Not.Nullable();              //, map => map.NotNullable(true));
            Map(x => x.Firstname);
            Map(x => x.Lastname);
            Map(x => x.Middlename);
            Map(x => x.Payfrequency);
            Map(x => x.Hourlypayrate);
            Map(x => x.Dailyrate);
            Map(x => x.Hiredate);
            Map(x => x.Earnedincomecredit);
            Map(x => x.Earnedincomecreditchildren);
            Map(x => x.Maritalstatus);
            Map(x => x.Allowances);
            Map(x => x.Dependents);
            Map(x => x.Exemptions);
            Map(x => x.Flatfit);
            Map(x => x.Additionalwitholdingflag);
            Map(x => x.Additionalwitholdingamount);
            Map(x => x.Birthdate);
            Map(x => x.Race);
            Map(x => x.Sex);
            Map(x => x.Parttime);
            Map(x => x.Filingstatus);
            Map(x => x.State);
            Map(x => x.Uscitizen);
            Map(x => x.Createdt).Generated.Insert();
            Map(x => x.Createby);
            References(c => c.Payors, "payorId");
            //ManyToOne(x => x.Payors, map => { map.Column("payorID"); map.Cascade(Cascade.None); });
        }
        protected override FluentConfiguration InnerConfiguration(FluentConfiguration cfg)
        {
            if (this.AutomappingConfigurer == null)
            {
                return(cfg);
            }

            var autoMappingMetadataCollection = AutomappingConfigurer.GetAutomappingMetadata();
            var persistenceAssemblies         = autoMappingMetadataCollection
                                                .Select(metadata => Assembly.LoadFrom(metadata.AssemblyName));

            return(cfg.Mappings(
                       m => m.AutoMappings.Add(
                           AutoMap.Assemblies(new AutomappingConfigurationFilter(), persistenceAssemblies)
                           .Conventions
                           .Setup(c =>
            {
                //c.Add(PrimaryKey.Name.Is(x => "Id"));
                c.Add(ForeignKey.Format((x, t) => t.Name + "Id"));
                c.Add(DefaultLazy.Always());
                c.AddFromAssemblyOf <TablePluralizationConvention>();
            }))));
        }
예제 #21
0
        public static ISessionFactory CriarSessionFactory()
        {
            SqlConnectionStringBuilder conexao = null;

            try
            {
                if (_sessionFactory != null)
                {
                    return(_sessionFactory);
                }

                //Obtém a string de conexão descriptografada
                string connectionStringDecriptografada = null;

                try
                {
                    //TODO: Analisar esta questão
                    //connectionStringDecriptografada = Classe.DecriptografarStringConexao(ConfigurationManager.ConnectionStrings["stringConexaoMySQL"].ToString());
                    connectionStringDecriptografada = ConfigurationManager.ConnectionStrings["cnxSebraeAcademico"].ConnectionString;
                    conexao = new SqlConnectionStringBuilder(connectionStringDecriptografada);

                    if (conexao == null)
                    {
                        throw new ApplicationException("Verifique a string de conexao com o banco de dados. Não foi possivel localizar o banco de dados do site.");
                    }
                }
                catch
                {
                    //TODO: URGENTE: GERAR LOG DE ERROS PARA EU TOMAR UMA DECISAO
                    //TODO: LOGAR E MANDAR E-MAIL
                    //Criar um configurationException
                    throw new ApplicationException("Ocorreu um Problema no acesso ao banco de Dados. Verifique a string de Conexão");
                }

                IPersistenceConfigurer persistenceConfigurer = null;

                //Banco MYSQL

                string usuario, senha, database, servidor;
                usuario  = conexao.UserID;
                senha    = conexao.Password;
                database = conexao.InitialCatalog;
                servidor = conexao.DataSource;

                persistenceConfigurer = MsSqlConfiguration
                                        .MsSql2008
                                        .IsolationLevel(System.Data.IsolationLevel.ReadCommitted)
                                        //.DefaultSchema("trilha")
                                        .UseOuterJoin()



//#if DEBUG
                                        .ShowSql()
                                        .FormatSql()
//#endif

                                        .ConnectionString(c => c.Server(servidor).Username(usuario).Password(senha).Database(database))
                                        .UseReflectionOptimizer()
                                        .AdoNetBatchSize(250);

                var configFluent = FluentNHibernate.Cfg.Fluently.Configure()

                                   //ManagedWebSessionContext
                                   .CurrentSessionContext <WebSessionContext>()

                                   .Database(persistenceConfigurer)

                                   .Mappings(m =>
                {
                    //, DynamicUpdate.AlwaysTrue(), DynamicInsert.AlwaysTrue()
                    m.FluentMappings.Conventions.Add(DefaultLazy.Always());
                    m.FluentMappings.AddFromAssembly(Assembly.Load("Sebrae.Academico.BM"));
                }); //.ProxyFactoryFactory<NHibernate.ByteCode.Castle.ProxyFactoryFactory>();


                _sessionFactory = configFluent.BuildSessionFactory();
            }
            catch (ApplicationException ex)
            {
                //   cUtil.WriteLog(ex, ex.Message);
                throw ex;
            }
            catch (FluentConfigurationException ex)
            {
                throw ex;
                // cUtil.WriteLog(ex, ex.Message, "Verificar os Mapeamentos. Pois é possível que algum mapeamento esteja errado.");
                //  throw new AcessoAoBancoDeDadosException("Ocorreu um Erro no Acesso ao Sistema.");
            }
            //catch (MySqlException ex)
            //{
            //    cUtil.WriteLog(ex, ex.Message, "Pode ser erro de memória. Verificar.");
            //    throw new AcessoAoBancoDeDadosException("Ocorreu um Erro no Acesso ao Sistema.");
            //}
            catch (System.Exception ex)
            {
                //cUtil.WriteLog(ex, ex.Message);
                //   throw new AcessoAoBancoDeDadosException("Ocorreu um Erro no Acesso ao Sistema.");
            }

            return(_sessionFactory);
        }