private static string MakeKey(string aAssociation, string aRole) {
return aAssociation + "_/\_" + aRole;
}
public static void FixCascadeDeleteIssues(XmlDocument XDOC, XmlNode SSDLNode, XmlNode CSDLNode, ref bool aChanged) {
HashSet lst = new HashSet();
foreach (XmlNode SSDLChild in SSDLNode) {
if (SSDLChild.Name == "Association") {
foreach (XmlNode EndChild in SSDLChild) {
if (EndChild.Name == "End") {
foreach (XmlNode DeleteChild in EndChild) {
if (DeleteChild.Name == "OnDelete") {
var x = DeleteChild.Attributes.GetNamedItem("Action");
if (x.Value == "Cascade") {
lst.Add(MakeKey(SSDLChild.Attributes.GetNamedItem("Name").Value, EndChild.Attributes.GetNamedItem("Role").Value));
}
}
}
}
}
}
}
Dictionary FMaps = new Dictionary();
foreach (XmlNode CSDLChild in CSDLNode) {
if (CSDLChild.Name == "EntityContainer") {
foreach (XmlNode ContainerChild in CSDLChild) {
if (ContainerChild.Name == "AssociationSet") {
foreach (XmlNode EndChild in ContainerChild) {
if (EndChild.Name == "End") {
string Association = ContainerChild.Attributes.GetNamedItem("Name").Value;
string Role = EndChild.Attributes.GetNamedItem("Role").Value;
string EntitySet = EndChild.Attributes.GetNamedItem("EntitySet").Value;
FMaps.Add(MakeKey(Association, Role), EntitySet);
}
}
}
}
}
}
foreach (XmlNode CSDLChild in CSDLNode) {
if (CSDLChild.Name == "Association") {
string Association = CSDLChild.Attributes.GetNamedItem("Name").Value;
if (Association == "FK_DEV_PARENT_DEV_ID") {
Console.WriteLine("");
}
foreach (XmlNode EndChild in CSDLChild) {
if (EndChild.Name == "End") {
string Multiplicity = EndChild.Attributes.GetNamedItem("Multiplicity").Value;
if (Multiplicity == "*") {
continue;
}
string role = EndChild.Attributes.GetNamedItem("Role").Value;
string v;
if (FMaps.TryGetValue(MakeKey(Association, role), out v)) role = v;
string key = MakeKey(CSDLChild.Attributes.GetNamedItem("Name").Value, role);
if (lst.Contains(key)) {
bool hasdel = false;
foreach (XmlNode DeleteChild in EndChild) {
if (DeleteChild.Name == "OnDelete") {
var x = DeleteChild.Attributes.GetNamedItem("Action");
if (x.Value == "Cascade") {
hasdel = true;
}
}
}
if (!hasdel) {
XmlNode newSub = XDOC.CreateNode(XmlNodeType.Element, "OnDelete", NamespaceDelete);
XmlAttribute xa = XDOC.CreateAttribute("Action", null);
xa.Value = "Cascade";
newSub.Attributes.Append(xa);
EndChild.AppendChild(newSub);
aChanged = true;
}
}
}
}
}
}
}
Recent Comments