Inheritance: Entity
 public TenantFormViewModel(Tenant tenant)
 {
     Id = tenant.Id;
       Name = tenant.Name;
       Domain = tenant.Domain;
       ConnectionString = tenant.ConnectionString;
 }
        public ActionResult Create(TenantFormViewModel viewModel)
        {
            if (!ViewData.ModelState.IsValid) {
            TempData.SafeAdd(viewModel);
            return this.RedirectToAction(c => c.Create());
              }

              try {
            var tenant = new Tenant { Name = viewModel.Name, Domain = viewModel.Domain, ConnectionString = viewModel.ConnectionString};
            _tenantRepository.SaveOrUpdate(tenant);
            TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = string.Format("Successfully created tenant '{0}'", tenant.Name);
              }
              catch (Exception ex) {
            TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = string.Format("An error occurred creating the tenant: {0}", ex.Message);
            return this.RedirectToAction(c => c.Create());
              }

              return this.RedirectToAction(c => c.Index(null));
        }
        /// <summary>
        /// Initializes the multi tenant NHibernate session.
        /// </summary>
        /// <param name="mappingAssemblies">The mapping assemblies.</param>
        /// <param name="configFile">The tenant config file.</param>
        /// <param name="tenant">The tenant.</param>
        private static void InitializeMultiTenantNHibernateSession(string[] mappingAssemblies, string configFile, Tenant tenant)
        {
            var configProperties = new Dictionary<string, string>
                                {
                                  {"connection.connection_string", tenant.ConnectionString}
                                };

              NHibernateSession.AddConfiguration(tenant.Domain,
                                             mappingAssemblies,
                                             new MultiTenantAutoPersistenceModelGenerator().Generate(),
                                             configFile,
                                             configProperties,
                                             null, null);
        }