LinqToSqlを使用してノードのすべての親ノードを取得する方法がありますが、パフォーマンスにどれだけ悪いのか分かりません。 NodeTableから再帰的メソッドでLinqToSqlを使用していると、パフォーマンスが非常に悪いです。
:
public partial class Node
{
public List<Node> GetAllParents(IEnumerable<Node> records)
{
if (this.ParentID == 0)
{
// Reach the parent, so create the instance of the collection and brake recursive.
return new List<Node>();
}
var parent = records.First(p => p.ID == ParentID);
// create a collection from one item to concat it with the all parents.
IEnumerable<Node> lst = new Node[] { parent };
lst = lst.Concat(parent.GetAllParents(records));
return lst.ToList();
}
}
が、それは良いです!またはそれを改善するための任意のアイデア!
ありがとうございました。
このLINQ to Objectsはありませんか? – Ani
@Ani:いいえ、LinqToSQLによって生成された生成クラスの部分クラスです。 – Homam
実行時に実際に時間がかかり過ぎるまで、パフォーマンスを心配する必要はありません。この瞬間、ほとんどの時間をどこから失うかを見ることができます。 – Shimrod