Files
lserp_cs_5.0/插件库/Zhaizj.Framework/ORM/Operation/FindRelationOperation.cs
T
2026-07-10 15:25:05 +08:00

61 lines
2.2 KiB
C#

using System;
using System.Collections;
using System.Data;
using System.Text;
using Zhaizj.Framework.Data;
namespace Zhaizj.Framework.ORM.Operation {
internal class FindRelationOperation {
private static readonly ILog logger = LogManager.GetLogger( typeof( FindRelationOperation ) );
public static IList FindDataOther( Type throughType, Type t, String order, int id ) {
// 1029
ObjectInfo state = new ObjectInfo( throughType );
String relationPropertyName = state.EntityInfo.GetRelationPropertyName( t );
EntityPropertyInfo info = state.EntityInfo.FindRelationProperty( t );
state.Order = order;
state.include( info.Name );
return ObjectDB.Find( state, relationPropertyName + ".Id=" + id ).listChildren( info.Name );
}
public static String GetSameTypeIds( Type throughType, Type t, int id ) {
// 1029
ObjectInfo state = new ObjectInfo( throughType );
String relationPropertyName = state.EntityInfo.GetRelationPropertyName( t );
EntityPropertyInfo info = state.EntityInfo.FindRelationProperty( t );
String ids = ObjectDB.Find(state, relationPropertyName + ".Id=" + id ).get( info.Name + ".Id" );
EntityPropertyInfo property = state.EntityInfo.GetProperty( relationPropertyName );
String sql = String.Format( "select distinct {0} from {1} where {2} in ({3}) and {0}<>{4}", property.ColumnName, state.EntityInfo.TableName, info.ColumnName, ids, id );
IDbCommand command = DataFactory.GetCommand( sql, DbContext.getConnection( state.EntityInfo ) );
IDataReader rd = null;
StringBuilder builder = new StringBuilder();
try {
rd = command.ExecuteReader();
while (rd.Read()) {
builder.Append( rd[0] );
builder.Append( "," );
}
}
catch (Exception exception) {
logger.Error( exception.Message );
throw exception;
}
finally {
OrmHelper.CloseDataReader( rd );
}
return builder.ToString().TrimEnd( ',' );
}
}
}