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


C# Transaction.Persist方法代码示例

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


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

示例1: TestTransactionWithNestedCalls

		public void TestTransactionWithNestedCalls()
		{
			Transaction transaction = new Transaction();
			// create some variables to work with
			try
			{
				IList lists = MailingList.ListAll;
				foreach( MailingList list in lists )
				{
					Key key = Key.GetKey( true, list );
					IList members = transaction.RetrieveList( typeof(Member), key, null );
					foreach( Member member in members )
					{
						transaction.Persist( member );
					}
					transaction.Persist( list );
				}
				transaction.Commit();
			}
			catch( Exception e )
			{
				string x = e.Message;
				transaction.Rollback();
				throw;
			}
		}
开发者ID:arangas,项目名称:MediaPortal-1,代码行数:26,代码来源:TestList.cs

示例2: TestTransaction

		public void TestTransaction()
		{
			// create some variables to work with
			l1 = MailingList.Retrieve( 1 ); // reuse existing list
			Member member = new Member( l1.Id, "Trans", "[email protected]" );
			// create and populate the transaction
			Transaction t = new Transaction();
			t.Update( l1 );
			t.Persist( member );
			t.Commit();
			// try updates and deletes
			member.Name = "Action";
			t = new Transaction();
			t.Update( member );
			t.Remove( member );
			t.Commit();
		}
开发者ID:arangas,项目名称:MediaPortal-1,代码行数:17,代码来源:TestList.cs

示例3: Persist

		/// <summary>
		/// Recursively persist all objects in list. This method will do nothing for n:m relations.
		/// </summary>
		/// <param name="transaction">The transaction within which to execute statements.</param>
		public virtual void Persist( Transaction transaction )
		{
			if( viaMap == null )
			{
				foreach( IPersistent obj in this )
				{
					if( transaction != null )
					{
						transaction.Persist( obj );
					}
					else
					{
						obj.Persist();
					}
				}
			}
		}
开发者ID:arangas,项目名称:MediaPortal-1,代码行数:21,代码来源:GentleList.cs

示例4: Persist

		/// <summary>
		/// Persist the current instance to the database as part of the given transaction.
		/// </summary>
		/// <param name="transaction">The transaction in which to execute the operation.</param>
		public virtual void Persist( Transaction transaction )
		{
			Check.VerifyNotNull( transaction, Error.NullParameter, "transaction" );
			transaction.Persist( this );
		}
开发者ID:arangas,项目名称:MediaPortal-1,代码行数:9,代码来源:Persistent.cs

示例5: Add

		/// <summary>
		/// Add an object to the list. For 1:n relations, any references on the object being added
		/// to the parent of the list will be updated to match the parents current values, and the 
		/// object will be inserted if it is a new one. For n:m relations, a new relation object is
		/// created and inserted (the object itself is never persisted).
		/// </summary>
		/// <param name="transaction">The transaction within which to execute statements.</param>
		/// <param name="value">The object to add to the list</param>
		/// <param name="relatedObjects">A list of values to use when creating the n:m relation 
		/// object.</param>
		/// <returns>The index of the newly added object</returns>
		public virtual int Add( Transaction transaction, object value, params object[] relatedObjects )
		{
			Check.VerifyNotNull( value, Error.NullParameter, "value" );
			Check.Verify( containedMap.Type.Equals( value.GetType() ) ||
			              value.GetType().IsSubclassOf( containedMap.Type ),
			              Error.UnsupportedType, value.GetType() );
			// skip adding objects matching existing data
			object val = Find( Key.GetKey( broker, true, value ) );
			value = val ?? value;
			// manage 1:n relation
			if( viaInstances == null )
			{
				Check.Verify( relatedObjects == null || relatedObjects.Length == 0,
				              Error.NotImplemented, "Request incompatible with GentleList in OneToMany mode." );
				// manage added object
				IPersistent obj = value as IPersistent;
				if( ! obj.IsPersisted )
				{
					// first we update the foreign key property on the added object
					UpdateForeignKeyFields( value );
					if( transaction != null )
					{
						transaction.Persist( obj );
					}
					else
					{
						obj.Persist();
					}
				}
			}
			else
			{
				// manage n:m relation object - creates new relation object using parent and value
				object[] args = Merge( value, relatedObjects );
				viaInstances.Add( transaction, args );
			}
			// this bit ensures object uniqing by disallowing objects with identical PK 
			// from being in the list more than once
			if( val == null )
			{
				return base.Add( value );
			}
			else
			{
				return IndexOf( val );
			}
		}
开发者ID:arangas,项目名称:MediaPortal-1,代码行数:58,代码来源:GentleList.cs


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