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

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

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

Loading…
Cancel
Save