FluentNHibernate.PersistenceModel.AddMappingsFromAssembly C# (CSharp) Method

AddMappingsFromAssembly() public method

public AddMappingsFromAssembly ( Assembly assembly ) : void
assembly System.Reflection.Assembly
return void
        public void AddMappingsFromAssembly(Assembly assembly)
        {
            foreach (Type type in assembly.GetExportedTypes())
            {
                if (!type.IsGenericType && typeof(IClassMap).IsAssignableFrom(type))
                    Add(type);
            }
        }

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::AddMappingsFromAssembly