Business Intelligence Blog

Welcome on Business Intelligence Blog !!!

This blog is dedicated to Business Intelligence technologies under SAS9 and SQL Server 2005.

Calendrier

Novembre 2009
L M M J V S D
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
<< < > >>

MVP Blog

Recommander

W3C

  • Flux RSS des articles
Lundi 30 mars 2009
Sur la base de la proposition, l'ajout de récursivité va permettre d'analyser dynamiquement l'arbre :
____

private

List<TablePath> lookForChilds( TablePath root , TablePath parent)

{

 

List<TablePath> ltp = new List<TablePath>();

 

 

DataTable dt = _database.Tables[parent.TableName,parent.Schema].EnumForeignKeys();

 

foreach (DataRow dr in dt.Rows)

{

 

string tableName = dr[1].ToString();

 

string schemaName = dr[0].ToString();

 

string fkname = dr[2].ToString();

 

if (!(tableName.Equals(parent.TableName) &&

schemaName.Equals(parent.Schema))

)

{


____

Je teste le parent afin de ne pas partir en récursion infinie liée à un éventuel Parent-Chlid ou association :

____

log.Info(

"scanning now " + tableName);

 

TablePath tp = new TablePath();

tp._database = parent._database;

tp._server = parent._server;

tp.TableName = dr[1].ToString();

tp.Schema = schemaName;

tp.ForeignKey = fkname;

tp._childs =

this.lookForChilds(root, tp);

ltp.Add(tp);

}

 

else

{

log.Info(

"preventing infiniteRecursion on " + tableName);

}

 

}

 

return ltp;

}


____


En passant, nous remplissons la ForeignKey impliquée. L'ensemble se restitue toujours avec la méthode AdaptTablePath() :

____

 

private void AdaptTablePath(ref TreeNode node, TablePath tablePath)

{

node.Text = tablePath.TableName +

" via < " +tablePath.ForeignKey +" >";

 

if (tablePath.Childs != null)

{

 

foreach (TablePath tp in tablePath.Childs)

{

 

TreeNode childNode = new TreeNode(tp.TableName );

AdaptTablePath(

ref childNode, tp);

node.Nodes.Add(childNode);

}

}

}


____

En mode restitué :
____

____
Par Renaud Harduin - Publié dans : SMO
Ecrire un commentaire - Voir les commentaires - Recommander
Retour à l'accueil
Créer un blog sur over-blog.com - Contact - C.G.U. - Rémunération en droits d'auteur - Signaler un abus