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


C# Configuration.AddResource方法代码示例

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


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

示例1: ConfigureNHibernate

        protected virtual void ConfigureNHibernate()
        {
            var configuration = new Configuration()
                .SetProperties(new Dictionary<string, string>
                {
                    {Environment.Dialect, typeof (MsSql2005Dialect).AssemblyQualifiedName},
                    {Environment.ProxyFactoryFactoryClass, typeof (ProxyFactoryFactory).AssemblyQualifiedName},
                    {Environment.ConnectionString, RootContext.GetConnectionStringFor(TenantId)},
                });
            var customMapping = GetMappingFrom(Assembly);
            var added = new HashSet<string>();
            foreach (var mapping in customMapping)
            {
                configuration.AddResource(mapping, Assembly);
                added.Add(GetEntityName(mapping));
            } 
            var coreMapping = GetMappingFrom(typeof(AbstractBootStrapper).Assembly);
            foreach (var mapping in coreMapping)
            {
                if (added.Add(GetEntityName(mapping)) == false)
                    continue;//already there
                configuration.AddResource(mapping, typeof (AbstractBootStrapper).Assembly);
            }

            container.Kernel.AddComponentInstance<Configuration>(configuration);

            ISessionFactory sessionFactory = configuration.BuildSessionFactory();
            container.Kernel.AddComponentInstance<ISessionFactory>(sessionFactory);
        }
开发者ID:JackWangCUMT,项目名称:rhino-tools,代码行数:29,代码来源:AbstractBootStrapper.cs

示例2: Connect

        public static void Connect()
        {
            ServerConsole.WriteLine("Database connecting...", MessageLevel.ODBC);

            //create config
            ServerConsole.WriteLine("Connecting to KalAuth...", MessageLevel.ODBC);
            Configuration cfg = new Configuration().Configure("kalauth.cfg.xml");

            //load resources
            ServerConsole.WriteLine("Loading resources", MessageLevel.ODBC);
            cfg.AddResource(@"KalSharp.Account.hbm.xml", System.Reflection.Assembly.GetExecutingAssembly());

            //building config
            KalAuth = cfg.BuildSessionFactory();
            ServerConsole.WriteLine("Connected to KalAuth", MessageLevel.ODBC);

            //create config
            ServerConsole.WriteLine("Connecting to KalDB...", MessageLevel.ODBC);
            Configuration cfg2 = new Configuration().Configure("kaldb.cfg.xml");

            //load resources
            ServerConsole.WriteLine("Loading resources", MessageLevel.ODBC);
            cfg2.AddResource(@"KalSharp.Player.hbm.xml", System.Reflection.Assembly.GetExecutingAssembly());
            cfg2.AddResource(@"KalSharp.PlayerDeleted.hbm.xml", System.Reflection.Assembly.GetExecutingAssembly());
            cfg2.AddResource(@"KalSharp.Worlds.Items.Item.hbm.xml", System.Reflection.Assembly.GetExecutingAssembly());

            //building config
            KalDB = cfg2.BuildSessionFactory();
            ServerConsole.WriteLine("Connected to KalDB", MessageLevel.ODBC);
        }
开发者ID:BeshoyFD,项目名称:kalsharp,代码行数:30,代码来源:Database.cs

示例3: SetUp

		public virtual void SetUp()
		{
			Configuration cfg = new Configuration();
			Assembly dm = Assembly.GetAssembly(typeof(Simple));
			cfg.AddResource("NHibernate.DomainModel.Simple.hbm.xml", dm);
			cfg.AddResource("NHibernate.DomainModel.NHSpecific.SimpleComponent.hbm.xml", dm);
			cfg.AddResource("NHibernate.DomainModel.Multi.hbm.xml", dm);

			factory = cfg.BuildSessionFactory();
			factoryImpl = (ISessionFactoryImplementor) factory;
			dialect = factoryImpl.Dialect;
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:12,代码来源:BaseExpressionFixture.cs

示例4: WrongPropertyNameForCamelcaseShouldThrow

		public void WrongPropertyNameForCamelcaseShouldThrow()
		{
			//default-access="field.camelcase" on property
			var cfg = new Configuration();
			Assert.Throws<MappingException>(() =>
				cfg.AddResource(ns + "DogMapping.hbm.xml", Assembly.GetExecutingAssembly()));
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:7,代码来源:Fixture.cs

示例5: SupportTypedefInReturnScalarElements

		public void SupportTypedefInReturnScalarElements()
		{
			var cfg = new Configuration();
			Assembly assembly = Assembly.GetExecutingAssembly();
			cfg.AddResource("NHibernate.Test.NHSpecificTest.NH1605.Mappings.hbm.xml", assembly);
			using (cfg.BuildSessionFactory()) {}
		}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:7,代码来源:Fixture.cs

示例6: MisspelledPropertyName

		public void MisspelledPropertyName() 
		{
			bool excCaught = false;

			// add a resource that has a bad mapping
			string resource = "NHibernate.Test.MappingExceptions.A.PropertyNotFound.hbm.xml";
			Configuration cfg = new Configuration();
			try 
			{
				cfg.AddResource( resource, this.GetType().Assembly );
				cfg.BuildSessionFactory();
			}
			catch( MappingException me ) 
			{
				//"Problem trying to set property type by reflection"
				// "Could not find a getter for property 'Naame' in class 'NHibernate.Test.MappingExceptions.A'"
				Assert.IsTrue( me.InnerException is MappingException );
				Assert.IsTrue( me.InnerException.InnerException is PropertyNotFoundException );

				Exception inner = me.InnerException.InnerException;
				Assert.IsTrue( inner.Message.IndexOf( "Naame" ) > 0, "should contain name of missing property 'Naame' in exception" );
				Assert.IsTrue( inner.Message.IndexOf( "NHibernate.Test.MappingExceptions.A" ) > 0, "should contain name of class that is missing the property" );
				excCaught = true;
			}

			Assert.IsTrue( excCaught, "Should have caught the MappingException that contains the property not found exception." );
		}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:27,代码来源:PropertyNotFoundExceptionFixture.cs

示例7: MisspelledPropertyName

		public void MisspelledPropertyName()
		{
			bool excCaught = false;

			// add a resource that has a bad mapping
			string resource = "NHibernate.Test.MappingExceptions.A.PropertyNotFound.hbm.xml";
			Configuration cfg = new Configuration();
			try
			{
				cfg.AddResource(resource, GetType().Assembly);
				cfg.BuildSessionFactory();
			}
			catch (MappingException me)
			{
				PropertyNotFoundException found = null;
				Exception find = me;
				while (find != null)
				{
					found = find as PropertyNotFoundException;
					find = find.InnerException;
				}
				Assert.IsNotNull(found, "The PropertyNotFoundException is not present in the Exception tree.");
				Assert.AreEqual("Naame", found.PropertyName, "should contain name of missing property 'Naame' in exception");
				Assert.AreEqual(typeof(A), found.TargetType, "should contain name of class that is missing the property");
				excCaught = true;
			}

			Assert.IsTrue(excCaught, "Should have caught the MappingException that contains the property not found exception.");
		}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:29,代码来源:PropertyNotFoundExceptionFixture.cs

示例8: MissingSuper

		public void MissingSuper()
		{
			Configuration cfg = new Configuration();

			try
			{
				cfg.AddResource(BaseForMappings + "Extendshbm.Customer.hbm.xml", typeof (ExtendsFixture).Assembly);
				Assert.That(cfg.GetClassMapping(typeof (Customer).FullName), Is.Null, "cannot be in the configuration yet!");
				cfg.AddResource(BaseForMappings + "Extendshbm.Employee.hbm.xml", typeof (ExtendsFixture).Assembly);

				cfg.BuildSessionFactory();

				Assert.Fail("Should not be able to build sessionfactory without a Person");
			}
			catch (HibernateException) {}
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:16,代码来源:ExtendsFixture.cs

示例9: IncrementGeneratorShouldIncludeClassLevelSchemaWhenGettingNextId

		public void IncrementGeneratorShouldIncludeClassLevelSchemaWhenGettingNextId()
		{
			System.Type thisType = GetType();
			Assembly thisAssembly = thisType.Assembly;

			Configuration cfg = new Configuration();
			cfg.AddResource(thisType.Namespace + ".Mappings.hbm.xml", thisAssembly);

			PersistentClass persistentClass = cfg.GetClassMapping(typeof(TestNH1061));
			// We know the ID generator is an IncrementGenerator.  The dialect does
			// not play a big role here, so just use the MsSql2000Dialect.
			IncrementGenerator generator =
				(IncrementGenerator)
				persistentClass.Identifier.CreateIdentifierGenerator(new Dialect.MsSql2000Dialect(), null, null, null);

			// I could not find a good seam to crack to test this.
			// This is not ideal as we are reflecting into a private variable to test.
			// On the other hand, the IncrementGenerator is rather stable, so I don't
			// think this would be a huge problem.
			// Having said that, if someone sees this and have a better idea to test,
			// please feel free to change it.
			FieldInfo sqlFieldInfo = generator.GetType().GetField("sql", BindingFlags.NonPublic | BindingFlags.Instance);
			string sql = (string)sqlFieldInfo.GetValue(generator);

			Assert.AreEqual("select max(Id) from test.TestNH1061", sql);
		}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:26,代码来源:Fixture.cs

示例10: NwaitingForSuper

		public void NwaitingForSuper()
		{
			Configuration cfg = new Configuration();

			cfg.AddResource(BaseForMappings + "Extendshbm.Customer.hbm.xml", typeof (ExtendsFixture).Assembly);
			Assert.That(cfg.GetClassMapping(typeof (Customer).FullName), Is.Null, "cannot be in the configuration yet!");

			cfg.AddResource(BaseForMappings + "Extendshbm.Employee.hbm.xml", typeof (ExtendsFixture).Assembly);
			Assert.That(cfg.GetClassMapping(typeof (Employee).FullName), Is.Null, "cannot be in the configuration yet!");

			cfg.AddResource(BaseForMappings + "Extendshbm.Person.hbm.xml", typeof (ExtendsFixture).Assembly);

			cfg.BuildMappings();
			Assert.That(cfg.GetClassMapping(typeof (Customer).FullName), Is.Not.Null);
			Assert.That(cfg.GetClassMapping(typeof (Person).FullName), Is.Not.Null);
			Assert.That(cfg.GetClassMapping(typeof (Employee).FullName), Is.Not.Null);
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:17,代码来源:ExtendsFixture.cs

示例11: CanLoadMappingWithNotNullIgnore

		public void CanLoadMappingWithNotNullIgnore()
		{
			var cfg = new Configuration();
			if (TestConfigurationHelper.hibernateConfigFile != null)
				cfg.Configure(TestConfigurationHelper.hibernateConfigFile);
			Assert.DoesNotThrow(
				() => cfg.AddResource("NHibernate.Test.NHSpecificTest.NH1255.Mappings.hbm.xml", typeof (Customer).Assembly));
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:8,代码来源:Fixture.cs

示例12: ValidateQuickStart

		public void ValidateQuickStart() 
		{
			Configuration cfg = new Configuration();
			cfg.AddResource( "NHibernate.Examples.ForumQuestions.T1078029.Member.hbm.xml", Assembly.Load("NHibernate.Examples") );
			
			ISessionFactory factory = cfg.BuildSessionFactory();
			
		}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:8,代码来源:MemberFixture.cs

示例13: ClassMissingDefaultCtor

		public void ClassMissingDefaultCtor()
		{
			// add a resource that doesn't exist
			string resource = "NHibernate.Test.MappingExceptions.MissingDefCtor.hbm.xml";
			Configuration cfg = new Configuration();
			cfg.AddResource(resource, this.GetType().Assembly);
			Assert.Throws<InstantiationException>(() =>cfg.BuildSessionFactory());
		}
开发者ID:tkellogg,项目名称:NHibernate3-withProxyHooks,代码行数:8,代码来源:MissingDefCtorFixture.cs

示例14: OrderingAddResources

		public void OrderingAddResources()
		{
			Configuration cfg = new Configuration();
			foreach (string res in Resources)
			{
				cfg.AddResource(res, MyAssembly);
			}
			cfg.BuildSessionFactory().Close();
		}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:9,代码来源:NH952Fixture.cs

示例15: AllInOne

		public void AllInOne()
		{
			Configuration cfg = new Configuration();

			cfg.AddResource(BaseForMappings + "Extendshbm.allinone.hbm.xml", typeof(ExtendsFixture).Assembly);
			Assert.That(cfg.GetClassMapping(typeof (Customer).FullName), Is.Not.Null);
			Assert.That(cfg.GetClassMapping(typeof(Person).FullName), Is.Not.Null);
			Assert.That(cfg.GetClassMapping(typeof(Employee).FullName), Is.Not.Null);
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:9,代码来源:ExtendsFixture.cs


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