FluentNHibernate.PersistenceModel.Configure C# (CSharp) Method

Configure() public method

public Configure ( NHibernate.Cfg.Configuration cfg ) : void
cfg NHibernate.Cfg.Configuration
return void
        public virtual void Configure(Configuration cfg)
        {
            EnsureMappingsBuilt();

            foreach (var mapping in compiledMappings)
            {
                var serializer = new MappingXmlSerializer();
                XmlDocument document = serializer.Serialize(mapping);

                if (cfg.GetClassMapping(mapping.Classes.First().Type) == null)
                    cfg.AddDocument(document);
            }
        }

Usage Example

Exemplo n.º 1
0
        public static void MyClassInitialize(TestContext testContext)
        {
            try {
                IPersistenceConfigurer persistenceConfigurer = MySQLConfiguration.Standard.ConnectionString(c => c.Is("Server=localhost;Database=basicproject;User ID=root;Password=1234")).ShowSql();
                // initialize nhibernate with persistance configurer properties
                Configuration cfg = persistenceConfigurer.ConfigureProperties(new Configuration());

                // add mappings definition to nhibernate configuration
                var persistenceModel = new PersistenceModel();
                persistenceModel.AddMappingsFromAssembly(Assembly.Load("BasicProject.NHibernateInfra.Implementation"));
                persistenceModel.Configure(cfg);
                // set session factory field which is to be used in tests
                _sessionFactory = cfg.BuildSessionFactory();
            } catch (ReflectionTypeLoadException ex) {
                StringBuilder sb = new StringBuilder();
                foreach (Exception exSub in ex.LoaderExceptions) {
                    sb.AppendLine(exSub.Message);
                    if (exSub is FileNotFoundException) {
                        FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog)) {
                            sb.AppendLine("Fusion Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                string errorMessage = sb.ToString();
                //Display or log the error based on your application.
            }
        }
All Usage Examples Of FluentNHibernate.PersistenceModel::Configure