0
我試圖發現數據庫結構,產生某種波蘇斯的,SMO DependencyWalker,許多一對多的關係問題
我用這個片段,發現相關的表,
var result = new ArrayList();
DependencyWalker w = new DependencyWalker(server);
DependencyTree tree = w.DiscoverDependencies(new SqlSmoObject[]{tbl}, DependencyType.Children);
DependencyCollection depends = w.WalkDependencies(tree);
foreach (DependencyCollectionNode dcn in depends)
{
//System.Windows.Forms.MessageBox.Show(tbl.Name + " -> " + dcn.Urn.Parent);
if (dcn.Urn.Type == "Table" && dcn.Urn.GetNameForType("Table") != tbl.Name)
{
var tblName = dcn.Urn.GetNameForType("Table");
result.Add(tblName);
}
}
return result;
這工作正常數據庫中的每個表,除了那些具有Many-to-Many
關係
例如
Car
CarColor
Employee
CarOwnerHistory
在CarOwnerHistory
,我的關係既Car
和Employee
,每Car
有CarColor
,
雖然CarColor
無關與CarOwnerHistory
,該DependencyCollection
它得到CarOwnerHistory
這個參考是生成的代碼
public class Car {
public virtual IList<CarOwner> CarOwner { get; set; }
public virtual CarColor CarColor { get; set; }
}
public class CarColor {
public virtual IList<CarOwner> CarOwner { get; set;} //:(Why ???
public virtual IList<Car> Car { get; set;}
}
public class CarOwner {
public virtual Car Car { get; set; }
public virtual Employee Employee { get; set; }
}
這是一個錯誤?如果是這樣,是否有任何工作?