当前位置: 首页>>代码示例>>C#>>正文


C# NHibernate.Cfg.Configuration.AddInputStream方法代码示例

本文整理汇总了C#中NHibernate.Cfg.Configuration.AddInputStream方法的典型用法代码示例。如果您正苦于以下问题:C# NHibernate.Cfg.Configuration.AddInputStream方法的具体用法?C# NHibernate.Cfg.Configuration.AddInputStream怎么用?C# NHibernate.Cfg.Configuration.AddInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NHibernate.Cfg.Configuration的用法示例。


在下文中一共展示了NHibernate.Cfg.Configuration.AddInputStream方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MyClassInitialize

        public static void MyClassInitialize(TestContext testContext)
        {
            // define mapping schema
            HbmSerializer.Default.HbmAssembly = typeof(Product).Assembly.GetName().FullName;
            //HbmSerializer.Default.HbmNamespace = typeof( Product ).Namespace;
            HbmSerializer.Default.HbmAutoImport = true;
            HbmSerializer.Default.Validate = true;
            HbmSerializer.Default.WriteDateComment = false;
            HbmSerializer.Default.HbmDefaultAccess = "field";
            //HbmSerializer.Default.Serialize(typeof(Product).Assembly, "output.hbm.xml"); // serialize mapping xml into file to spectate it

            // create configuration and load assembly
            NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
            //cfg.Properties[NHibernate.Cfg.Environment.CollectionTypeFactoryClass] = typeof(Net4CollectionTypeFactory).AssemblyQualifiedName;
            cfg.Configure();
            //cfg.AddAssembly( typeof( Product ).Assembly ); // use this only, if hbm.xml exists in the assembly
            cfg.AddInputStream(HbmSerializer.Default.Serialize(typeof(Product).Assembly)); // ez bármikor müxik, de lassabb

            try
            {
                SchemaValidator schemaValidator = new SchemaValidator(cfg);
                schemaValidator.Validate(); // validate the database schema
            }
            catch (Exception)
            {
                SchemaUpdate schemaUpdater = new SchemaUpdate(cfg); // try to update schema
                schemaUpdater.Execute(false, true);
                if (schemaUpdater.Exceptions.Count > 0)
                {
                    throw new Exception("FAILED TO UPDATE SCHEMA");
                }
            }

            //SchemaExport export = new SchemaExport(cfg);
            //export.Execute( false, true, false );
            //new SchemaExport( cfg ).Execute( false, true, false );
            mSessionFactory = cfg.BuildSessionFactory();
        }
开发者ID:JZO001,项目名称:Forge,代码行数:38,代码来源:EntityTest.cs

示例2: GenerateMappingFromAttributesIfNeeded

		/// <summary>
		/// If <paramref name="targetAssembly"/> has a reference on
		/// <c>NHibernate.Mapping.Attributes</c> : use the NHibernate mapping
		/// attributes contained in that assembly to update NHibernate
		/// configuration (<paramref name="cfg"/>). Else do nothing
		/// </summary>
		/// <remarks>
		/// To avoid an unnecessary dependency on the library
		/// <c>NHibernate.Mapping.Attributes.dll</c> when using this
		/// facility without NHibernate mapping attributes, all calls to that
		/// library are made using reflexion.
		/// </remarks>
		/// <param name="cfg">NHibernate configuration</param>
		/// <param name="targetAssembly">Target assembly name</param>
		protected void GenerateMappingFromAttributesIfNeeded(Configuration cfg, String targetAssembly)
		{
			//Get an array of all assemblies referenced by targetAssembly
			AssemblyName[] refAssemblies = Assembly.Load(targetAssembly).GetReferencedAssemblies();

			//If assembly "NHibernate.Mapping.Attributes" is referenced in targetAssembly
			if (Array.Exists(refAssemblies,delegate(AssemblyName an) { return an.Name.Equals(NHMappingAttributesAssemblyName); }))
			{
				//Obtains, by reflexion, the necessary tools to generate NH mapping from attributes
				Type HbmSerializerType =
					Type.GetType(String.Concat(NHMappingAttributesAssemblyName, ".HbmSerializer, ", NHMappingAttributesAssemblyName));
				Object hbmSerializer = Activator.CreateInstance(HbmSerializerType);
				PropertyInfo validate = HbmSerializerType.GetProperty("Validate");
				MethodInfo serialize = HbmSerializerType.GetMethod("Serialize", new[] {typeof (Assembly)});

				//Enable validation of mapping documents generated from the mapping attributes
				validate.SetValue(hbmSerializer, true, null);

				//Generates a stream of mapping documents from all decorated classes in targetAssembly and add it to NH config
				cfg.AddInputStream((MemoryStream) serialize.Invoke(hbmSerializer, new object[] {Assembly.Load(targetAssembly)}));
			}
		}
开发者ID:hconceicao,项目名称:Castle.Facilities.NHibernateIntegration3,代码行数:36,代码来源:DefaultConfigurationBuilder.cs

示例3: BuildSessionFactory

        private static ISessionFactory BuildSessionFactory(string factoryCfg)
        {
            MemoryStream stream = new MemoryStream(); // where the xml will be written
            HbmSerializer.Default.Validate = true; // Enable validation (optional)

            // Set any specific values for the <hibernate-mapping> element here

            // Set the 'default-access' attribute
            // This matches our naming convention for member fields
            HbmSerializer.Default.HbmDefaultAccess = "field.camelcase-underscore";

            // Set the 'auto-import' attribute off
            // This forces NHibernate to use fully qualified class names (i.e. full namespace prefixes)
            HbmSerializer.Default.HbmAutoImport = false;

            // Here, we serialize all decorated classes
            GetNhibernateClasses(stream);

            stream.Position = 0; // Rewind

            // TODO: Implement a better method (i.e. configurable) of getting the resulting file out
#if DEBUG
            try
            {
                stream.WriteTo(new FileStream(@"ProjectTracker.hbm.xml", FileMode.Create));
            }
            catch (UnauthorizedAccessException e)
            {
                //user trying to access the path is probably coming from IIS and it does not have permission to create the file
                //to catch it and carry on
                e.ToString(); //prevent r# warning
            }
#endif

			Configuration configuration = new Configuration();;
			configuration.Configure(factoryCfg);
			configuration.AddInputStream(stream); // Use the stream here
            stream.Close();

            // Now use the configuration to build the Session Factory
			return configuration.BuildSessionFactory();
        }
开发者ID:transformersprimeabcxyz,项目名称:cslacontrib-MarimerLLC,代码行数:42,代码来源:Cfg.cs


注:本文中的NHibernate.Cfg.Configuration.AddInputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。