Example #1
0
        private static void Main(string[] args)
        {
            Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2012)
            .Mappings(m => m.FluentMappings.AddFromAssemblyOf <User>()
                      .Conventions.Add(Table.Is(x => "tbl" + x.EntityType.Name))
                      .Conventions.Add(DefaultAccess.CamelCaseField(CamelCasePrefix.Underscore))
                      .Conventions.Add(ForeignKey.EndsWith("_Id")))
            .ExposeConfiguration(BuildSchema).BuildConfiguration();

            Console.WriteLine("enter for exit");
            Console.ReadLine();
        }
Example #2
0
        protected override void PostProcessConfiguration(Configuration config)
        {
            base.PostProcessConfiguration(config);

            Fluently.Configure(config).Mappings(m => {
                foreach (string assemblyName in FluentMappingAssemblies)
                {
                    /* HBM Mappings der Konfiguration hinzufügen. */
                    m.HbmMappings.AddFromAssembly(Assembly.Load(assemblyName));

                    /* Fluent Mappings der Konfiguration hinzufügen. */
                    m.FluentMappings.AddFromAssembly(Assembly.Load(assemblyName))
                    .Conventions.Add(Table.Is(x => "tbl" + x.EntityType.Name))
                    .Conventions.Add(DefaultAccess.CamelCaseField(CamelCasePrefix.Underscore));
                }
            }).BuildConfiguration();
            // noch vor BuilConfiguration() steht: .ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true)) (wenn es benötigt wird.
        }
Example #3
0
        public static ISessionFactory BuildSessionFactory()
        {
            var configuration = Fluently
                                .Configure()
                                .Database(
                MsSqlConfiguration.MsSql2008
                .ConnectionString(str => str.FromConnectionStringWithKey("sparrow"))
                .ShowSql
                )
                                .Mappings(m =>
            {
                m.AutoMappings
                .Add(
                    AutoMap.AssemblyOf <User>(new AutoMapConfiguration())
                    .IgnoreBase <EntityBase>()
                    .Conventions.Add(
                        new EnumConvention(),
                        new NotNullConvention(),
                        ConventionBuilder.Class.Always(c => c.Schema("dbo")),
                        ConventionBuilder.Id.Always(id => id.GeneratedBy.GuidComb()),
                        ConventionBuilder.HasMany.Always(many =>
                {
                    many.Inverse();
                    many.Cascade.AllDeleteOrphan();
                }),
                        PrimaryKey.Name.Is(id => "ID"),
                        ForeignKey.EndsWith("ID"),
                        DefaultAccess.CamelCaseField(CamelCasePrefix.Underscore)
                        )
                    );
            })
                                .BuildConfiguration();

            // Uncomment to automatically generate database tables.
            // new SchemaExport(configuration).Create(false, true);

            return(configuration.BuildSessionFactory());
        }