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


C# School.AcceptChanges方法代码示例

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


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

示例1: Update

        /// <summary>
        /// 	Update an existing row in the datasource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">School.Entities.Students object to update.</param>
        /// <remarks>
        ///		After updating the datasource, the School.Entities.Students object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Update(TransactionManager transactionManager, School.Entities.Students entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Students_Update", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@Id", DbType.Int32, entity.Id );
            database.AddInParameter(commandWrapper, "@Name", DbType.String, entity.Name );
            database.AddInParameter(commandWrapper, "@Address", DbType.String, entity.Address );
            database.AddInParameter(commandWrapper, "@ClassId", DbType.Int32, entity.ClassId );
            database.AddInParameter(commandWrapper, "@Birthdate", DbType.Date, entity.Birthdate );
            database.AddInParameter(commandWrapper, "@Gender", DbType.String, entity.Gender );

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            //Stop Tracking Now that it has been updated and persisted.
            if (DataRepository.Provider.EnableEntityTracking)
            {
                EntityManager.StopTracking(entity.EntityTrackingKey);
            }

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity));

            return Convert.ToBoolean(results);
        }
开发者ID:mario-loza,项目名称:School,代码行数:52,代码来源:SqlStudentsProviderBase.generated.cs

示例2: Insert

        /// <summary>
        /// 	Inserts a School.Entities.Students object into the datasource using a transaction.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">School.Entities.Students object to insert.</param>
        /// <remarks>
        ///		After inserting into the datasource, the School.Entities.Students object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>	
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Insert(TransactionManager transactionManager, School.Entities.Students entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Students_Insert", _useStoredProcedure);

            database.AddOutParameter(commandWrapper, "@Id", DbType.Int32, 4);
            database.AddInParameter(commandWrapper, "@Name", DbType.String, entity.Name );
            database.AddInParameter(commandWrapper, "@Address", DbType.String, entity.Address );
            database.AddInParameter(commandWrapper, "@ClassId", DbType.Int32, entity.ClassId );
            database.AddInParameter(commandWrapper, "@Birthdate", DbType.Date, entity.Birthdate );
            database.AddInParameter(commandWrapper, "@Gender", DbType.String, entity.Gender );

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            object _id = database.GetParameterValue(commandWrapper, "@Id");
            entity.Id = (System.Int32)_id;

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity));

            return Convert.ToBoolean(results);
        }
开发者ID:mario-loza,项目名称:School,代码行数:49,代码来源:SqlStudentsProviderBase.generated.cs


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