Browse Source

Fix null reference when creating new EF data model file.

Do not add an EntityTypeMapping element if it already exists.
Fix intermittent error were the EF data model view content
does not have a workbench window when the file is renamed
on save.
pull/37/head
Matt Ward 13 years ago
parent
commit
5ff1f88f1f
  1. 25
      src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/MSLIO.cs
  2. 3
      src/Main/Base/Project/Src/Services/File/FileService.cs

25
src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/MSLIO.cs

@ -25,10 +25,6 @@ namespace ICSharpCode.Data.EDMDesigner.Core.IO
{ {
public class MSLIO : IO public class MSLIO : IO
{ {
#region Methods
#region Read
public static XDocument GenerateTypeMapping(XDocument mslDocument) public static XDocument GenerateTypeMapping(XDocument mslDocument)
{ {
XElement mappingElement = mslDocument.Element(XName.Get("Mapping", mslNamespace.NamespaceName)); XElement mappingElement = mslDocument.Element(XName.Get("Mapping", mslNamespace.NamespaceName));
@ -41,8 +37,10 @@ namespace ICSharpCode.Data.EDMDesigner.Core.IO
if (entityContainerMappingElement == null || entityContainerMappingElement.IsEmpty) if (entityContainerMappingElement == null || entityContainerMappingElement.IsEmpty)
return null; return null;
foreach (XElement entitySetMapping in entityContainerMappingElement.Elements(mslNamespace + "EntitySetMapping")) foreach (XElement entitySetMapping in entityContainerMappingElement.Elements(mslNamespace + "EntitySetMapping")) {
{ if (entitySetMapping.HasEntityTypeMappingChildElement())
continue;
string name = entitySetMapping.Attribute("Name").Value; string name = entitySetMapping.Attribute("Name").Value;
string storeEntitySet = entitySetMapping.Attribute("StoreEntitySet").Value; string storeEntitySet = entitySetMapping.Attribute("StoreEntitySet").Value;
string typeName = entitySetMapping.Attribute("TypeName").Value; string typeName = entitySetMapping.Attribute("TypeName").Value;
@ -61,7 +59,7 @@ namespace ICSharpCode.Data.EDMDesigner.Core.IO
return mslDocument; return mslDocument;
} }
public static CSDLContainer IntegrateMSLInCSDLContainer(CSDLContainer csdlContainer, SSDLContainer ssdlContainer, XElement edmxRuntime) public static CSDLContainer IntegrateMSLInCSDLContainer(CSDLContainer csdlContainer, SSDLContainer ssdlContainer, XElement edmxRuntime)
{ {
XElement mappingsElement = edmxRuntime.Element(XName.Get("Mappings", edmxNamespace.NamespaceName)); XElement mappingsElement = edmxRuntime.Element(XName.Get("Mappings", edmxNamespace.NamespaceName));
@ -263,10 +261,6 @@ namespace ICSharpCode.Data.EDMDesigner.Core.IO
} }
} }
#endregion
#region Write
public static XElement Write(EDM edm) public static XElement Write(EDM edm)
{ {
CSDLContainer csdlContainer = edm.CSDLContainer; CSDLContainer csdlContainer = edm.CSDLContainer;
@ -533,10 +527,6 @@ namespace ICSharpCode.Data.EDMDesigner.Core.IO
new XAttribute("ColumnName", result.Value)); new XAttribute("ColumnName", result.Value));
} }
} }
#endregion
#endregion
} }
#region Extension methods #region Extension methods
@ -560,6 +550,11 @@ namespace ICSharpCode.Data.EDMDesigner.Core.IO
return element; return element;
} }
public static bool HasEntityTypeMappingChildElement(this XElement entitySetMapping)
{
return entitySetMapping.Elements().Any(e => e.Name.LocalName == "EntityTypeMapping");
}
} }
#endregion #endregion

3
src/Main/Base/Project/Src/Services/File/FileService.cs

@ -149,7 +149,8 @@ namespace ICSharpCode.SharpDevelop
if (openedFileDict.ContainsKey(newName)) { if (openedFileDict.ContainsKey(newName)) {
OpenedFile oldFile = openedFileDict[newName]; OpenedFile oldFile = openedFileDict[newName];
if (oldFile.CurrentView != null) { if (oldFile.CurrentView != null) {
oldFile.CurrentView.WorkbenchWindow.CloseWindow(true); if (oldFile.CurrentView.WorkbenchWindow != null)
oldFile.CurrentView.WorkbenchWindow.CloseWindow(true);
} else { } else {
throw new ArgumentException("there already is a file with the newName"); throw new ArgumentException("there already is a file with the newName");
} }

Loading…
Cancel
Save