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


C# Column.GetIncomingValueConversionExpression方法代码示例

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


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

示例1: writeExecuteInsertOrUpdateMethod

        private static void writeExecuteInsertOrUpdateMethod(
            DBConnection cn, string tableName, bool isRevisionHistoryClass, IEnumerable<Column> keyColumns, Column identityColumn)
        {
            writer.WriteLine( "private void executeInsertOrUpdate() {" );
            writer.WriteLine( "try {" );
            if( isRevisionHistoryClass )
                writer.WriteLine( DataAccessStatics.GetConnectionExpression( database ) + ".ExecuteInTransaction( delegate {" );

            // insert

            writer.WriteLine( "if( modType == ModificationType.Insert ) {" );

            // If this is a revision history table, write code to insert a new revision when a row is inserted into this table.
            if( isRevisionHistoryClass ) {
                writer.WriteLine( "var revisionHistorySetup = RevisionHistoryStatics.SystemProvider;" );
                writer.WriteLine( getColumnFieldName( columns.PrimaryKeyAndRevisionIdColumn ) + ".Value = revisionHistorySetup.GetNextMainSequenceValue();" );
                writer.WriteLine(
                    "revisionHistorySetup.InsertRevision( System.Convert.ToInt32( " + getColumnFieldName( columns.PrimaryKeyAndRevisionIdColumn ) +
                    ".Value ), System.Convert.ToInt32( " + getColumnFieldName( columns.PrimaryKeyAndRevisionIdColumn ) + ".Value ), " +
                    DataAccessStatics.GetConnectionExpression( database ) + ".GetUserTransactionId() );" );
            }

            writer.WriteLine( "var insert = new InlineInsert( \"" + tableName + "\" );" );
            writer.WriteLine( "addColumnModifications( insert );" );
            if( identityColumn != null ) {
                // One reason the ChangeType call is necessary: SQL Server identities always come back as decimal, and you can't cast a boxed decimal to an int.
                writer.WriteLine(
                    "{0}.Value = {1};".FormatWith(
                        getColumnFieldName( identityColumn ),
                        identityColumn.GetIncomingValueConversionExpression(
                            "EwlStatics.ChangeType( insert.Execute( {0} ), typeof( {1} ) )".FormatWith(
                                DataAccessStatics.GetConnectionExpression( database ),
                                identityColumn.UnconvertedDataTypeName ) ) ) );
            }
            else
                writer.WriteLine( "insert.Execute( " + DataAccessStatics.GetConnectionExpression( database ) + " );" );

            // Future calls to Execute should perform updates, not inserts. Use the values of key columns as conditions.
            writer.WriteLine( "modType = ModificationType.Update;" );
            writer.WriteLine( "conditions = new List<" + DataAccessStatics.GetTableConditionInterfaceName( cn, database, tableName ) + ">();" );
            foreach( var column in keyColumns ) {
                writer.WriteLine(
                    "conditions.Add( new " + DataAccessStatics.GetEqualityConditionClassName( cn, database, tableName, column ) + "( " +
                    EwlStatics.GetCSharpIdentifierSimple( column.PascalCasedNameExceptForOracle ) + " ) );" );
            }

            writer.WriteLine( "}" ); // if insert

            // update
            writer.WriteLine( "else {" );
            if( isRevisionHistoryClass )
                writer.WriteLine( "copyLatestRevisions( conditions );" );
            writer.WriteLine( "var update = new InlineUpdate( \"" + tableName + "\" );" );
            writer.WriteLine( "addColumnModifications( update );" );
            writer.WriteLine( "conditions.ForEach( condition => update.AddCondition( condition.CommandCondition ) );" );
            if( isRevisionHistoryClass )
                writer.WriteLine( "update.AddCondition( getLatestRevisionsCondition() );" );
            writer.WriteLine( "update.Execute( " + DataAccessStatics.GetConnectionExpression( database ) + " );" );
            writer.WriteLine( "}" ); // else

            if( isRevisionHistoryClass )
                writer.WriteLine( "} );" ); // cn.ExecuteInTransaction
            writer.WriteLine( "}" ); // try

            writer.WriteLine( "catch( System.Exception e ) {" );
            writer.WriteLine( "rethrowAsDataModificationExceptionIfNecessary( e );" );
            writer.WriteLine( "throw;" );
            writer.WriteLine( "}" ); // catch

            writer.WriteLine( "}" ); // method
        }
开发者ID:enduracode,项目名称:enterprise-web-library,代码行数:71,代码来源:StandardModificationStatics.cs


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