コード例 #1
0
 /// <summary>
 /// Map the convention.
 /// </summary>
 /// <param name="finder">Convention finder.</param>
 public virtual void Build(IConventionFinder finder)
 {
     finder.Add <PrimaryKeyConvention>();
     finder.Add <PrimaryKeyGuidConvention>();
     finder.Add(DefaultCascade.None());
     finder.Add(ForeignKey.EndsWith("Id"));
 }
コード例 #2
0
        public override FluentConfiguration CreateConfiguration()
        {
            FluentConfiguration.InitializeFromConfigMsSql(Configuration, ConfigSectionName);
            FluentConfiguration.AddMappingsFromAssemblyOf <ExampleSessionFactoryBuilder>(
                PrimaryKey.Name.Is(x => "ID"),
                Table.Is(x => x.EntityType.Name + "s"),
                ForeignKey.EndsWith("ID"),
                ForeignKeyConstraintNameConvention.WithConstraintNameConvention(),
                DefaultCascade.None());

            return(FluentConfiguration);
        }
コード例 #3
0
        public static void ConfigureMappings(MappingConfiguration mappingConfiguration, params IMappingConfigurationContributor[] configurationContributors)
        {
            mappingConfiguration.FluentMappings
            .Conventions.Add(
                ForeignKey.EndsWith("Id"),
                PrimaryKey.Name.Is(x => x.EntityType.Name + "Id"),
                DefaultCascade.None());

            foreach (var configurationContributor in configurationContributors)
            {
                configurationContributor.ConfigureMappings(mappingConfiguration);
            }
        }
コード例 #4
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());
        }
コード例 #5
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());
     });
 }
コード例 #6
0
ファイル: SessionManager.cs プロジェクト: lurienanofab/lnf
        private void HandleMappings(MappingConfiguration cfg)
        {
            cfg.HbmMappings.AddFromAssemblyOf <SessionManager <T> >();

            cfg.FluentMappings
            .AddFromAssembly(GetType().Assembly)
            .Conventions.AddAssembly(GetType().Assembly)
            .Conventions.Add(
                AutoImport.Always(),
                ForeignKey.EndsWith("ID"),
                LazyLoad.Always(),
                DefaultCascade.None(),
                DynamicInsert.AlwaysTrue(),
                DynamicUpdate.AlwaysTrue());
        }
コード例 #7
0
        public static ISessionFactory GetFactory(Type classMapping, string dbKey, string connectionString)
        {
            if (!factories.ContainsKey(dbKey))
            {
                lock (syncObject)
                {
                    try
                    {
                        // incluido o exemplo com SQL server e MYsql
                        if (!factories.ContainsKey(dbKey))
                        {
                            ISessionFactory factory;
                            switch (dbKey)
                            {
                            case DatabaseKeys.MYSQL:
                                factory = Fluently.Configure()
                                          .Database(MySQLConfiguration.Standard.ConnectionString(connectionString))
                                          .Mappings(x => x.FluentMappings.AddFromAssembly(classMapping.Assembly).Conventions.Add(DefaultCascade.None()))
                                          .BuildSessionFactory();
                                factories.Add(dbKey, factory);
                                break;

                            case DatabaseKeys.SQLSERVER:
                                factory = Fluently.Configure()
                                          .Database(MsSqlConfiguration.MsSql2008.FormatSql().ShowSql().AdoNetBatchSize(50).ConnectionString(connectionString))
                                          .Mappings(x => x.FluentMappings.AddFromAssembly(classMapping.Assembly).Conventions.Add(DefaultCascade.None()))
                                          .BuildSessionFactory();
                                factories.Add(dbKey, factory);
                                break;

                            case DatabaseKeys.ORACLE:
                                throw new NotImplementedException();

                            default:
                                break;
                            }
                        }
                    }
                    catch (System.Exception)
                    {
                        throw;
                    }
                }
            }
            return(factories[dbKey]);
        }
コード例 #8
0
        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);
        }