init lserp cs 5.0
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using Zhaizj.Framework;
|
||||
using Zhaizj.Framework.Data;
|
||||
using Zhaizj.Framework.Log;
|
||||
|
||||
namespace Zhaizj.Framework.ORM.Operation {
|
||||
|
||||
internal class CountOperation {
|
||||
|
||||
private static readonly ILog logger = LogManager.GetLogger( typeof( CountOperation ) );
|
||||
|
||||
public static int Count( Type t ) {
|
||||
return Count( t, "" );
|
||||
}
|
||||
|
||||
public static int Count( Type t, String condition ) {
|
||||
return Count( condition, Entity.GetInfo( t ) );
|
||||
}
|
||||
|
||||
private static int Count( String condition, EntityInfo entityInfo ) {
|
||||
String countSql;
|
||||
int result = 0;
|
||||
SqlBuilder builder = new SqlBuilder( entityInfo );
|
||||
if (strUtil.IsNullOrEmpty( condition )) {
|
||||
countSql = String.Format( "select count(*) from {0}", entityInfo.TableName );
|
||||
}
|
||||
else {
|
||||
countSql = builder.GetCountSql( condition );
|
||||
}
|
||||
logger.Info( LoggerUtil.SqlPrefix+"[Count(String condition) Sql]:" + countSql );
|
||||
IDbCommand command = DataFactory.GetCommand( countSql, DbContext.getConnection( entityInfo ) );
|
||||
try {
|
||||
result = cvt.ToInt( command.ExecuteScalar() );
|
||||
}
|
||||
catch (Exception exception) {
|
||||
logger.Error( exception.Message );
|
||||
throw exception;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user