private void HandlChildCollections(Type type, SqlCommand cmd, SqlSelectClause sqlSelect) { List<PropertyInfo> childCollectionPropertList = type.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PersistentCollection))).ToList(); foreach (PropertyInfo propertyInfo in childCollectionPropertList) { Type collectionType = propertyInfo.PropertyType; Type baseType = collectionType.BaseType; Type genericType = baseType.GetGenericArguments()[0]; SqlSelectClause thisSqlSelect = new SqlSelectClause(collectionType); SqlStatement sqlStatement = new SqlStatement(thisSqlSelect, type, genericType); sqlSelect.SqlStatements.Add(sqlStatement); this.HandlChildCollections(genericType, cmd, thisSqlSelect); } }
public SqlCommand Build() { SqlCommand cmd = new SqlCommand(); PersistentClass persistentClassAttribute = (PersistentClass)this.m_Type.GetCustomAttributes(typeof(PersistentClass), false).Single(); PropertyInfo primaryKeyPropertyInfo = this.m_Type.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PersistentPrimaryKeyProperty))).Single(); StringPropertyBridge primaryKeyPropertyBridge = new StringPropertyBridge(primaryKeyPropertyInfo, this.m_PrimaryKeyValue); primaryKeyPropertyBridge.SetSqlParameter(cmd); SqlSelectClause sqlSelect = new SqlSelectClause(this.m_Type); SqlParameterClause sqlParameterStatement = new SqlParameterClause(this.m_Type, this.m_PrimaryKeyValue); SqlStatement sqlStatement = new SqlStatement(sqlParameterStatement, sqlSelect, this.m_Type); cmd.CommandText = sqlStatement.ToString(); return cmd; }