當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。