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


C# SqlCommandInfo.ToString方法代码示例

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


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

示例1: Insert

		/// <summary>
		/// Perform an SQL INSERT.
		/// </summary>
		/// <remarks>
		/// This for is used for all non-root tables as well as the root table
		/// in cases where the identifier value is known before the insert occurs.
		/// </remarks>
		protected void Insert(object id, object[] fields, bool[] notNull, int j,
			SqlCommandInfo sql, object obj, ISessionImplementor session)
		{
			if (IsInverseTable(j))
			{
				return;
			}

			//note: it is conceptually possible that a UserType could map null to
			//	  a non-null value, so the following is arguable:
			if (IsNullableTable(j) && IsAllNull(fields, j))
			{
				return;
			}

			if (log.IsDebugEnabled)
			{
				log.Debug("Inserting entity: " + MessageHelper.InfoString(this, id, Factory));
				if (j == 0 && IsVersioned)
				{
					log.Debug("Version: " + Versioning.GetVersion(fields, this));
				}
			}

			IExpectation expectation = Expectations.AppropriateExpectation(insertResultCheckStyles[j]);
			//bool callable = IsInsertCallable(j);
			// we can't batch joined inserts, *especially* not if it is an identity insert;
			// nor can we batch statements where the expectation is based on an output param
			bool useBatch = j == 0 && expectation.CanBeBatched;

			try
			{
				// Render the SQL query
				IDbCommand insertCmd = useBatch
																? session.Batcher.PrepareBatchCommand(sql.CommandType, sql.Text, sql.ParameterTypes)
																: session.Batcher.PrepareCommand(sql.CommandType, sql.Text, sql.ParameterTypes);

				try
				{
					int index = 0;
					//index += expectation.Prepare(insertCmd, factory.ConnectionProvider.Driver);

					// Write the values of the field onto the prepared statement - we MUST use the
					// state at the time the insert was issued (cos of foreign key constraints).
					// Not necessarily the obect's current state

					Dehydrate(id, fields, null, notNull, propertyColumnInsertable, j, insertCmd, session, index);

					if (useBatch)
					{
						session.Batcher.AddToBatch(expectation);
					}
					else
					{
						expectation.VerifyOutcomeNonBatched(session.Batcher.ExecuteNonQuery(insertCmd), insertCmd);
					}
				}
				catch (Exception e)
				{
					if (useBatch)
					{
						session.Batcher.AbortBatch(e);
					}
					throw;
				}
				finally
				{
					if (!useBatch)
					{
						session.Batcher.CloseCommand(insertCmd, null);
					}
				}
			}
			catch (DbException sqle)
			{
				var exceptionContext = new AdoExceptionContextInfo
				                       	{
				                       		SqlException = sqle,
				                       		Message = "could not insert: " + MessageHelper.InfoString(this, id),
				                       		Sql = sql.ToString(),
				                       		EntityName = EntityName,
				                       		EntityId = id
				                       	};
				throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, exceptionContext);
			}
		}
开发者ID:rbirkby,项目名称:nhibernate-core,代码行数:93,代码来源:AbstractEntityPersister.cs


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