/// <summary> /// 数据初始化 /// </summary> /// <param name="inputConfiguartionPacker"></param> /// <param name="lstTypeNeedMap"></param> private void PrepareData(ConfigurationPacker inputConfiguartionPacker, List <Type> lstTypeNeedMap) { m_hibernateConfig = new Configuration(); m_useConfiguartionPacker = inputConfiguartionPacker; m_useAutoMappingHandler = new EntityAutoMappingHandler(); Type baseType = typeof(BaseEntity); //过滤基类 var useFullType = from n in lstTypeNeedMap where baseType.IsAssignableFrom(n) select n; foreach (var oneType in useFullType) { m_useAutoMappingHandler.RegiesType(oneType); } //获得映射 var useHbm = m_useAutoMappingHandler.GetHbmMapping(); //设置配置 m_useConfiguartionPacker.AddToNHibernateConfiguration(m_hibernateConfig); //注册映射 m_hibernateConfig.AddDeserializedMapping(useHbm, Guid.NewGuid().ToString()); //创建会话工厂 m_useSessionFactory = m_hibernateConfig.BuildSessionFactory(); }
/// <summary> /// 构造管理器 /// </summary> /// <param name="inputConfiguartionPacker">输入的数据库设置</param> public ORMManger(ConfigurationPacker inputConfiguartionPacker) { Assembly useAssembly = Assembly.GetCallingAssembly(); Type useBaseType = typeof(BaseEntity); var useTypes = from n in useAssembly.GetTypes() where useBaseType.IsAssignableFrom(n) select n; PrepareData(inputConfiguartionPacker, useTypes.ToList()); }
/// <summary> /// 构造管理器 /// </summary> /// <param name="inputConfiguartionPacker">输入的数据库设置</param> /// <param name="lstTypeNeedMap">需注册的类型</param> public ORMManger(ConfigurationPacker inputConfiguartionPacker, List <Type> lstTypeNeedMap) { PrepareData(inputConfiguartionPacker, lstTypeNeedMap); }