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


C# EntityInfo.GetColumnName方法代码示例

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


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

示例1: Update

        public static void Update( IEntity obj, String[] arrPropertyName, EntityInfo entityInfo )
        {
            if (obj == null) throw new ArgumentNullException();
            StringBuilder builder = new StringBuilder( String.Empty );
            builder.Append( "update " );
            builder.Append( entityInfo.TableName );
            builder.Append( " set " );

            for (int i = 0; i < arrPropertyName.Length; i++) {
                String columnName = entityInfo.GetColumnName( arrPropertyName[i] );
                builder.Append( columnName );
                builder.Append( "=" );
                builder.Append( entityInfo.Dialect.GetParameter( columnName ) );
                builder.Append( "," );
            }
            builder.Append( " where Id=" );
            builder.Append( entityInfo.Dialect.GetParameter( "Id" ) );

            String commandText = builder.ToString().Replace( ", where", " where" );
            logger.Info( LoggerUtil.SqlPrefix+entityInfo.Name + "[" + entityInfo.TableName + "] Update Sql:" + commandText );

            List<IInterceptor> ilist = MappingClass.Instance.InterceptorList;
            for (int i = 0; i < ilist.Count; i++) {
                ilist[i].BeforUpdate( obj );
            }

            IDbCommand cmd = DataFactory.GetCommand( commandText, DbContext.getConnection( entityInfo ) );
            for (int i = 0; i < arrPropertyName.Length; i++) {
                Object parameterValue = obj.get( arrPropertyName[i] );
                String columnName = entityInfo.GetColumnName( arrPropertyName[i] );
                DataFactory.SetParameter( cmd, columnName, parameterValue );
            }
            int id = obj.Id;
            DataFactory.SetParameter( cmd, "Id", id );
            cmd.ExecuteNonQuery();

            for (int i = 0; i < ilist.Count; i++) {
                ilist[i].AfterUpdate( obj );
            }

            // update cache  timestamp
            CacheTime.updateTable( entityInfo.Type );

            CacheUtil.CheckCountCache( "insert", obj, entityInfo );
        }
开发者ID:nust03,项目名称:xcore,代码行数:45,代码来源:UpdateOperation.cs

示例2: Update

        public static void Update( IEntity obj, String[] arrPropertyName, EntityInfo entityInfo ) {
            if (obj == null) throw new ArgumentNullException();
            StringBuilder builder = new StringBuilder( String.Empty );
            builder.Append( "update " );
            builder.Append( entityInfo.TableName );
            builder.Append( " set " );
            for (int i = 0; i < arrPropertyName.Length; i++)
            {
                String columnName = entityInfo.GetColumnName(arrPropertyName[i]);
                builder.Append(columnName);
                builder.Append("=");
                builder.Append(entityInfo.Dialect.GetParameter(columnName));
                builder.Append(",");
            }
            builder.Append( " where Id=" );
            builder.Append( entityInfo.Dialect.GetParameter( "Id" ) );

            String commandText = builder.ToString().Replace( ", where", " where" );
            logger.Info( LoggerUtil.SqlPrefix+entityInfo.Name + "[" + entityInfo.TableName + "] Update Sql:" + commandText );

            List<IInterceptor> ilist = MappingClass.Instance.InterceptorList;
            for (int i = 0; i < ilist.Count; i++) {
                ilist[i].BeforUpdate( obj );
            }

            var conn = DbContext.getConnection(entityInfo);
            if (conn.State == System.Data.ConnectionState.Closed)
            {
                conn.Open();
                OrmHelper.initCount++;
                LogManager.GetLogger("Class:System.ORM.Operation.UpdateOperation Method:Update").Info("数据库连接已开启【" + OrmHelper.initCount + "】");
            }
            IDbCommand cmd = DataFactory.GetCommand(commandText, conn);
            for (int i = 0; i < arrPropertyName.Length; i++)
            {
                Object parameterValue = obj.get(arrPropertyName[i]);
                String columnName = entityInfo.GetColumnName(arrPropertyName[i]);
                DataFactory.SetParameter(cmd, columnName, parameterValue);
            }
            int id = obj.Id;
            DataFactory.SetParameter(cmd, "Id", id);
            cmd.ExecuteNonQuery();

            if (!DbContext.shouldTransaction())
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                    conn.Dispose();
                    OrmHelper.clostCount++;
                    LogManager.GetLogger("Class:System.ORM.Operation.UpdateOperation Method:Update").Info("数据库连接已关闭【" + OrmHelper.clostCount + "】");
                }
            }

            for (int i = 0; i < ilist.Count; i++) {
                ilist[i].AfterUpdate( obj );
            }

            // update cache  timestamp
            CacheTime.updateTable( entityInfo.Type );


            CacheUtil.CheckCountCache( "insert", obj, entityInfo );
        }
开发者ID:mfz888,项目名称:xcore,代码行数:64,代码来源:UpdateOperation.cs


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