本文整理汇总了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 );
}
示例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 );
}