diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Addin/Templates/Files/CSharp.EDMX.xft b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Addin/Templates/Files/CSharp.EDMX.xft index d4a76a3972..2984065bbb 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Addin/Templates/Files/CSharp.EDMX.xft +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Addin/Templates/Files/CSharp.EDMX.xft @@ -20,10 +20,9 @@ ${Path} -> Full path of the file --> - - + @@ -36,6 +35,7 @@ ]]> + diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/ICSharpCode.Data.Core.UI.csproj b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/ICSharpCode.Data.Core.UI.csproj index 6550cb56f9..394783cd34 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/ICSharpCode.Data.Core.UI.csproj +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/ICSharpCode.Data.Core.UI.csproj @@ -161,6 +161,7 @@ LoadingCircle.xaml + ConnectionWizardWindow.xaml diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/UserControls/WizardErrorUserControl.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/UserControls/WizardErrorUserControl.cs new file mode 100644 index 0000000000..4099c85e03 --- /dev/null +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/UserControls/WizardErrorUserControl.cs @@ -0,0 +1,41 @@ +#region Usings + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +#endregion + +namespace ICSharpCode.Data.Core.UI.UserControls +{ + public class WizardErrorUserControl : WizardUserControl + { + #region Fields + + private Exception _exception = null; + + #endregion + + #region Properties + + public override sealed bool CanFinish + { + get { return false; } + } + + public Exception Exception + { + get { return _exception; } + set + { + _exception = value; + OnPropertyChanged("Exception"); + } + } + + public int PreviousIndex { get; set; } + + #endregion + } +} diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/UserControls/WizardUserControl.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/UserControls/WizardUserControl.cs index ae7157f7de..a5dca0fd7b 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/UserControls/WizardUserControl.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/UserControls/WizardUserControl.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System; using System.Collections.Generic; @@ -59,6 +62,14 @@ namespace ICSharpCode.Data.Core.UI.UserControls get { throw new NotImplementedException(); } } + /// + /// Returns if this WizardUserControl is dependent of its predecessor user control. + /// + public virtual bool IsDependentOnPredecessor + { + get { return true; } + } + /// /// Returns if this WizardUserControl can finish the WizardWindow. /// @@ -108,6 +119,19 @@ namespace ICSharpCode.Data.Core.UI.UserControls #region Methods + internal void Activate(bool activatedFromPredecessor) + { + if (activatedFromPredecessor && IsDependentOnPredecessor) + { + OnActivateFromPredecessor(); + } + + OnActivate(); + } + + public virtual void OnActivateFromPredecessor() + { } + public virtual void OnActivate() { } diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/Windows/WizardWindowInnards.xaml.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/Windows/WizardWindowInnards.xaml.cs index 6ed5a1b6e2..844fc3d957 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/Windows/WizardWindowInnards.xaml.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/Windows/WizardWindowInnards.xaml.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System; using System.Collections.Generic; @@ -32,8 +35,10 @@ namespace ICSharpCode.Data.Core.UI.Windows DependencyProperty.Register("IsReadyForNextStep", typeof(bool), typeof(WizardWindowInnards), new FrameworkPropertyMetadata(false, IsReadyForNextStep_Changed)); private WizardWindow _wizardWindow = null; private ObservableCollection _wizardUserControls = new ObservableCollection(); + private WizardErrorUserControl _wizardErrorUserControl = null; private WizardUserControl _currentWizardUserControl = null; private int _currentIndex = 0; + private int _previousIndex = 0; #endregion @@ -47,6 +52,15 @@ namespace ICSharpCode.Data.Core.UI.Windows get { return _wizardUserControls; } } + /// + /// Gets or sets the current WizardWindows' user control for displaying errors. + /// + public WizardErrorUserControl WizardErrorUserControl + { + get { return _wizardErrorUserControl; } + set { _wizardErrorUserControl = value; } + } + /// /// Returns the current WizardUserControls index of the WizardWindow. /// @@ -55,6 +69,7 @@ namespace ICSharpCode.Data.Core.UI.Windows get { return _currentIndex; } protected set { + _previousIndex = _currentIndex; _currentIndex = value; _currentWizardUserControl = null; OnPropertyChanged("CurrentIndex"); @@ -73,10 +88,28 @@ namespace ICSharpCode.Data.Core.UI.Windows return _currentWizardUserControl; else { - _currentWizardUserControl = _wizardUserControls.FirstOrDefault(wuc => wuc.Index == _currentIndex); - BindingBase binding = new Binding("IsReadyForNextStep") { Source = _currentWizardUserControl }; - SetBinding(WizardWindowInnards.IsReadyForNextStepProperty, binding); - ToggleEnabledButtons(); + + if (_currentIndex == -1) + { + _currentWizardUserControl = _wizardErrorUserControl; + } + else + { + _currentWizardUserControl = _wizardUserControls.FirstOrDefault(wuc => wuc.Index == _currentIndex); + BindingBase binding = new Binding("IsReadyForNextStep") { Source = _currentWizardUserControl }; + SetBinding(WizardWindowInnards.IsReadyForNextStepProperty, binding); + } + + if (_currentWizardUserControl != null) + { + if (_currentIndex != -1 && _currentIndex - 1 == _previousIndex) + _currentWizardUserControl.Activate(true); + else + _currentWizardUserControl.Activate(false); + + ToggleEnabledButtons(); + } + return _currentWizardUserControl; } } @@ -106,7 +139,7 @@ namespace ICSharpCode.Data.Core.UI.Windows if (!IsInitialized) return; - if (CurrentIndex == 0) + if (_currentIndex == 0) { btnPrevious.IsEnabled = false; } @@ -115,7 +148,7 @@ namespace ICSharpCode.Data.Core.UI.Windows btnPrevious.IsEnabled = true; } - if (CurrentIndex == _wizardUserControls.Count - 1) + if (_currentIndex == -1 || _currentIndex == _wizardUserControls.Count - 1) { btnNext.IsEnabled = false; } @@ -134,8 +167,6 @@ namespace ICSharpCode.Data.Core.UI.Windows } else btnFinish.IsEnabled = false; - - CurrentWizardUserControl.OnActivate(); } #endregion @@ -157,6 +188,10 @@ namespace ICSharpCode.Data.Core.UI.Windows { if (CurrentIndex == 0) return; + else if (CurrentIndex == -1) + { + CurrentIndex = _wizardErrorUserControl.PreviousIndex; + } else { CurrentIndex--; @@ -175,7 +210,25 @@ namespace ICSharpCode.Data.Core.UI.Windows private void btnFinish_Click(object sender, RoutedEventArgs e) { - _wizardWindow.OnFinished(); + try + { + _wizardWindow.OnFinished(); + } + catch (Exception ex) + { + if (_wizardErrorUserControl != null) + { + _wizardErrorUserControl.Exception = ex; + _wizardErrorUserControl.PreviousIndex = _currentIndex; + CurrentIndex = -1; + + return; + } + else + { + throw ex; + } + } _wizardWindow.DialogResult = true; _wizardWindow.Close(); diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/DatabaseObjects/Column.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/DatabaseObjects/Column.cs index 14b228357d..eade320c7f 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/DatabaseObjects/Column.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/DatabaseObjects/Column.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System; using System.Collections.Generic; @@ -191,6 +194,9 @@ namespace ICSharpCode.Data.Core.DatabaseObjects { get { + if (_parentTable.Constraints == null) + return false; + IConstraint constraint = _parentTable.Constraints.FirstOrDefault(constr => constr.FKColumns.FirstOrDefault(column => column.ColumnId == ColumnId && column.Name == Name) != null); if (constraint == null) diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/DatabaseObjects/DatabaseObjectsCollection.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/DatabaseObjects/DatabaseObjectsCollection.cs index 358e391d09..3d8c6dcdb1 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/DatabaseObjects/DatabaseObjectsCollection.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/DatabaseObjects/DatabaseObjectsCollection.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System; using System.Collections.Generic; @@ -31,6 +34,22 @@ namespace ICSharpCode.Data.Core.DatabaseObjects } } + public int SelectedItemsCount + { + get + { + int selectedItemsCount = 0; + + foreach (T item in this) + { + if (item.IsSelected) + selectedItemsCount++; + } + + return selectedItemsCount; + } + } + #endregion #region Methods diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/DatabaseObjects/View.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/DatabaseObjects/View.cs index 4dbf061d69..202e96f774 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/DatabaseObjects/View.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/DatabaseObjects/View.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System; using System.Collections.Generic; @@ -14,12 +17,23 @@ namespace ICSharpCode.Data.Core.DatabaseObjects { #region Fields + private string _query = string.Empty; private string _definingQuery = string.Empty; #endregion #region Properties + public string Query + { + get { return _query; } + set + { + _query = value; + OnPropertyChanged("Query"); + } + } + public string DefiningQuery { get { return _definingQuery; } diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/Interfaces/IView.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/Interfaces/IView.cs index c445f38813..8ec001c20d 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/Interfaces/IView.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/Interfaces/IView.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System; using System.Collections.Generic; @@ -11,6 +14,7 @@ namespace ICSharpCode.Data.Core.Interfaces { public interface IView : ITable { + string Query { get; set; } string DefiningQuery { get; set; } } } diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.DemoApp/ICSharpCode.Data.DemoApp.csproj b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.DemoApp/ICSharpCode.Data.DemoApp.csproj index 27eb7144ff..121e7555da 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.DemoApp/ICSharpCode.Data.DemoApp.csproj +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.DemoApp/ICSharpCode.Data.DemoApp.csproj @@ -59,6 +59,7 @@ + 4.0 diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/EDMObjects/SSDL/EntityType/EntityType.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/EDMObjects/SSDL/EntityType/EntityType.cs index de6a881e66..b4b8902ecb 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/EDMObjects/SSDL/EntityType/EntityType.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/EDMObjects/SSDL/EntityType/EntityType.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System; using System.Collections.Generic; @@ -43,7 +46,37 @@ namespace ICSharpCode.Data.EDMDesigner.Core.EDMObjects.SSDL.EntityType public string DefiningQuery { - get { return _definingQuery; } + get + { + if (StoreType == null || StoreType == SSDL.EntityType.StoreType.Tables) + return _definingQuery; + + if (string.IsNullOrEmpty(_definingQuery)) + { + string definingQuery = string.Empty; + + for (int i = 0; i < _properties.Count; i++) + { + if (string.IsNullOrEmpty(definingQuery)) + definingQuery += "SELECT \r"; + + definingQuery += string.Format("[{0}].[{1}] AS [{1}]", _entitySetName, _properties[i].Name); + + if (i < _properties.Count - 1) + { + definingQuery += ", \r"; + } + else + { + definingQuery += string.Format(" \rFROM [{0}].[{1}] AS [{1}]", Schema, _entitySetName); + } + } + + return definingQuery; + } + + return _definingQuery; + } set { _definingQuery = value; diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ICSharpCode.Data.EDMDesigner.Core.csproj b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ICSharpCode.Data.EDMDesigner.Core.csproj index 5de1e3c477..4119b1b09f 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ICSharpCode.Data.EDMDesigner.Core.csproj +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ICSharpCode.Data.EDMDesigner.Core.csproj @@ -165,6 +165,7 @@ + @@ -175,6 +176,9 @@ ChooseDatabaseObjectsUserControl.xaml + + EDMWizardErrorUserControl.xaml + @@ -185,6 +189,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/CSDLIO.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/CSDLIO.cs index a3864f64ea..996856c9ab 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/CSDLIO.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/CSDLIO.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System; using System.Linq; @@ -124,6 +127,7 @@ namespace ICSharpCode.Data.EDMDesigner.Core.IO ReadCSDLType(schemaElement, entityTypeElement, container, (TypeBase)entityType); return entityType; } + private static void ReadCSDLType(XElement schemaElement, XElement entityTypeElement, CSDLContainer container, TypeBase baseType) { if (baseType.Name == null) diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/EDMXIO.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/EDMXIO.cs index 67cff00f07..d6fa099e47 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/EDMXIO.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/EDMXIO.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System; using System.Linq; @@ -35,7 +38,7 @@ namespace ICSharpCode.Data.EDMDesigner.Core.IO private static EDM Read(XElement edmx, Action readMoreAction) { - XElement edmxRuntime = edmx.Element(XName.Get("Runtime", "http://schemas.microsoft.com/ado/2007/06/edmx")); + XElement edmxRuntime = edmx.Element(XName.Get("Runtime", edmxNamespace.NamespaceName)); SSDLContainer ssdlContainer = SSDLIO.ReadXElement(edmxRuntime); CSDLContainer csdlContainer = CSDLIO.ReadXElement(edmxRuntime); @@ -60,5 +63,18 @@ namespace ICSharpCode.Data.EDMDesigner.Core.IO readMoreAction(edmx); return edm; } + + public static XDocument WriteXDocument(XDocument ssdlXDocument, XDocument csdlXDocument, XDocument mslXDocument) + { + return new XDocument(new XDeclaration("1.0", "utf-8", null), + new XElement(edmxNamespace + "Edmx", new XAttribute("Version", "1.0"), new XAttribute(XNamespace.Xmlns + "edmx", edmxNamespace.NamespaceName), + new XElement(edmxNamespace + "Runtime", + new XElement(edmxNamespace + "StorageModels", + ssdlXDocument.Root), + new XElement(edmxNamespace + "ConceptualModels", + csdlXDocument.Root), + new XElement(edmxNamespace + "Mappings", + mslXDocument.Root)))); + } } } diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/IO.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/IO.cs index 375c7a047a..54dad01a3f 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/IO.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/IO.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System; using System.Linq; @@ -13,14 +16,14 @@ namespace ICSharpCode.Data.EDMDesigner.Core.IO { #region Namespace declarations - protected static XNamespace edmxNamespace = "http://schemas.microsoft.com/ado/2007/06/edmx"; - protected static XNamespace ssdlNamespace = "http://schemas.microsoft.com/ado/2006/04/edm/ssdl"; + protected static XNamespace edmxNamespace = "http://schemas.microsoft.com/ado/2008/10/edmx"; + protected static XNamespace ssdlNamespace = "http://schemas.microsoft.com/ado/2009/02/edm/ssdl"; protected static XNamespace storeNamespace = "http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator"; - protected static XNamespace csdlNamespace = "http://schemas.microsoft.com/ado/2006/04/edm"; + protected static XNamespace csdlNamespace = "http://schemas.microsoft.com/ado/2008/09/edm"; protected static XNamespace csdlCodeGenerationNamespace = "http://schemas.microsoft.com/ado/2006/04/codegeneration"; - protected static XNamespace mslNamespace = "urn:schemas-microsoft-com:windows:storage:mapping:CS"; + protected static XNamespace mslNamespace = "http://schemas.microsoft.com/ado/2008/09/mapping/cs"; #endregion diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/SSDLIO.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/SSDLIO.cs index 9f3b93c286..679a4b6bb0 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/SSDLIO.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/IO/SSDLIO.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System; using System.Collections.Generic; @@ -46,12 +49,12 @@ namespace ICSharpCode.Data.EDMDesigner.Core.IO { XElement entitySet = new XElement(ssdlNamespace + "EntitySet", new XAttribute("Name", entityType.EntitySetName), new XAttribute("EntityType", string.Concat(entityContainerNamespace, entityType.Name))) - .AddAttribute("Schema", entityType.Schema) + .AddAttribute(entityType.StoreType == StoreType.Views ? null : new XAttribute("Schema", entityType.Schema)) .AddAttribute("Table", entityType.Table) .AddAttribute(storeNamespace, "Name", entityType.StoreName) .AddAttribute(storeNamespace, "Schema", entityType.StoreSchema) .AddAttribute(storeNamespace, "Type", entityType.StoreType) - .AddElement(string.IsNullOrEmpty(entityType.DefiningQuery) ? null : new XElement("DefiningQuery", entityType.DefiningQuery)); + .AddElement(string.IsNullOrEmpty(entityType.DefiningQuery) ? null : new XElement(ssdlNamespace + "DefiningQuery", entityType.DefiningQuery)); entityContainer.Add(entitySet); } @@ -84,7 +87,9 @@ namespace ICSharpCode.Data.EDMDesigner.Core.IO foreach (Property property in entityType.Properties) { - if (property.IsKey) + // If we have a table then we set a key element if the current property is a primary key or part of a composite key. + // AND: If we have a view then we make a composite key of all non-nullable properties of the entity (VS2010 is also doing this). + if ((entityType.StoreType == StoreType.Tables && property.IsKey) || (entityType.StoreType == StoreType.Views && property.Nullable == false)) keys.Add(new XElement(ssdlNamespace + "PropertyRef", new XAttribute("Name", property.Name))); } diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ObjectModelConverters/EDMConverter.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ObjectModelConverters/EDMConverter.cs index 0961600e86..7ff032eabb 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ObjectModelConverters/EDMConverter.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ObjectModelConverters/EDMConverter.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System; using System.Collections.Generic; @@ -46,7 +49,6 @@ namespace ICSharpCode.Data.EDMDesigner.Core.ObjectModelConverters string filenameRump = Path.GetTempPath() + fileInfo.Name.Replace(fileInfo.Extension, string.Empty); string edmGenPath = RuntimeEnvironment.GetRuntimeDirectory() + "\\EdmGen.exe"; - edmGenPath = @"C:\Windows\Microsoft.NET\Framework\v3.5\EdmGen.exe"; Process process = new Process(); ProcessStartInfo processStartInfo = new ProcessStartInfo(); @@ -65,26 +67,15 @@ namespace ICSharpCode.Data.EDMDesigner.Core.ObjectModelConverters if (process.ExitCode != 0) { - throw new Exception("An error occured during generating the EDMX file.", new Exception(outputMessage)); + throw new ObjectModelConverterException(string.Format("An error occured during generating the EDMX file from \"{0}.ssdl\".", filenameRump), + outputMessage, ObjectModelConverterExceptionEnum.EDM); } XDocument csdlXDocument = XDocument.Load(filenameRump + ".csdl"); XDocument mslXDocument = XDocument.Load(filenameRump + ".msl"); mslXDocument = MSLIO.GenerateTypeMapping(mslXDocument); - XNamespace edmxNamespace = "http://schemas.microsoft.com/ado/2007/06/edmx"; - - XDocument edmXDocument = new XDocument(new XDeclaration("1.0", "utf-8", null), - new XElement(edmxNamespace + "Edmx", new XAttribute("Version", "1.0"), new XAttribute(XNamespace.Xmlns + "edmx", edmxNamespace.NamespaceName), - new XElement(edmxNamespace + "Runtime", - new XElement(edmxNamespace + "StorageModels", - ssdlXDocument.Root), - new XElement(edmxNamespace + "ConceptualModels", - csdlXDocument.Root), - new XElement(edmxNamespace + "Mappings", - mslXDocument.Root)))); - - return edmXDocument; + return EDMXIO.WriteXDocument(ssdlXDocument, csdlXDocument, mslXDocument); } private static string GetTempFilename() diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ObjectModelConverters/ObjectModelConverterException.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ObjectModelConverters/ObjectModelConverterException.cs new file mode 100644 index 0000000000..a6527c1824 --- /dev/null +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ObjectModelConverters/ObjectModelConverterException.cs @@ -0,0 +1,39 @@ +#region Usings + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +#endregion + +namespace ICSharpCode.Data.EDMDesigner.Core.ObjectModelConverters +{ + public enum ObjectModelConverterExceptionEnum + { + CSDL, + EDM, + SSDL + } + + public class ObjectModelConverterException : Exception + { + #region Constructor + + public ObjectModelConverterException(string message, string detail, ObjectModelConverterExceptionEnum type) : base(message) + { + Detail = detail; + ExceptionType = type; + } + + #endregion + + #region Properties + + public string FullMessage { get { return Message + "\n\nDetailed error message:\n" + Detail; } } + public string Detail { get; protected set; } + public ObjectModelConverterExceptionEnum ExceptionType { get; protected set; } + + #endregion + } +} diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ObjectModelConverters/SSDLConverter.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ObjectModelConverters/SSDLConverter.cs index 064f146460..d7eee8c72d 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ObjectModelConverters/SSDLConverter.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/ObjectModelConverters/SSDLConverter.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System.Collections.Generic; @@ -75,7 +78,9 @@ namespace ICSharpCode.Data.EDMDesigner.Core.ObjectModelConverters { Name = table.TableName, EntitySetName = table.TableName, - Schema = table.SchemaName + Schema = table.SchemaName, + StoreName = table.TableName, + StoreSchema = table.SchemaName }; if (table is IView) diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/Windows/EDMWizard/ChooseDatabaseObjectsUserControl.xaml.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/Windows/EDMWizard/ChooseDatabaseObjectsUserControl.xaml.cs index 9744cc4d89..3d01dce82e 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/Windows/EDMWizard/ChooseDatabaseObjectsUserControl.xaml.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/Windows/EDMWizard/ChooseDatabaseObjectsUserControl.xaml.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -49,7 +52,7 @@ namespace ICSharpCode.Data.EDMDesigner.Core.Windows.EDMWizard InitializeComponent(); } - public override void OnActivate() + public override void OnActivateFromPredecessor() { EDMWizardWindow edmWizardWindow = WizardWindow as EDMWizardWindow; if (edmWizardWindow.SelectedDatabase != null) diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/Windows/EDMWizard/EDMWizardErrorUserControl.xaml b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/Windows/EDMWizard/EDMWizardErrorUserControl.xaml new file mode 100644 index 0000000000..c1914b05d5 --- /dev/null +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/Windows/EDMWizard/EDMWizardErrorUserControl.xaml @@ -0,0 +1,14 @@ + + + + + + + + The following error(s) occured during generation of the Entity Data Model: + + + diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/Windows/EDMWizard/EDMWizardErrorUserControl.xaml.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/Windows/EDMWizard/EDMWizardErrorUserControl.xaml.cs new file mode 100644 index 0000000000..3ad04efb52 --- /dev/null +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/Windows/EDMWizard/EDMWizardErrorUserControl.xaml.cs @@ -0,0 +1,44 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using ICSharpCode.Data.Core.UI.UserControls; + +namespace ICSharpCode.Data.EDMDesigner.Core.Windows.EDMWizard +{ + /// + /// Interaction logic for EDMWizardErrorUserControl.xaml + /// + public partial class EDMWizardErrorUserControl : WizardErrorUserControl + { + public override string Title + { + get + { + return "Error while generating Entity Model"; + } + } + + public EDMWizardErrorUserControl() + { + InitializeComponent(); + } + + public override void OnActivate() + { + + } + } +} diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/Windows/EDMWizard/EDMWizardWindow.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/Windows/EDMWizard/EDMWizardWindow.cs index 49549b07ac..74adf5aa4f 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/Windows/EDMWizard/EDMWizardWindow.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.EDMDesigner.Core/Windows/EDMWizard/EDMWizardWindow.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System; using System.Collections.Generic; @@ -139,6 +142,7 @@ namespace ICSharpCode.Data.EDMDesigner.Core.Windows.EDMWizard Title = "Entity Framework Wizard"; Width = 640; Height = 480; + WizardWindowInnards.WizardErrorUserControl = new EDMWizardErrorUserControl(); AddWizardUserControl(); AddWizardUserControl(); @@ -147,23 +151,6 @@ namespace ICSharpCode.Data.EDMDesigner.Core.Windows.EDMWizard #endregion - #region Event handlers - - private void btnNewConnection_Click(object sender, RoutedEventArgs e) - { - ConnectionWizardWindow connectionWizardWindow = new ConnectionWizardWindow(); - connectionWizardWindow.Owner = this; - connectionWizardWindow.ShowDialog(); - - if (connectionWizardWindow.DialogResult.HasValue && connectionWizardWindow.DialogResult.Value) - { - _databases.Add(connectionWizardWindow.SelectedDatabase); - SelectedDatabase = connectionWizardWindow.SelectedDatabase; - } - } - - #endregion - #region Methods public override void OnFinished() diff --git a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.SQLServer/SQLServerDatabaseDriver.cs b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.SQLServer/SQLServerDatabaseDriver.cs index 7a23c2f4b3..1b11787e26 100644 --- a/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.SQLServer/SQLServerDatabaseDriver.cs +++ b/src/AddIns/DisplayBindings/Data/ICSharpCode.Data.SQLServer/SQLServerDatabaseDriver.cs @@ -1,4 +1,7 @@ -#region Usings +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +#region Usings using System; using System.Collections.Generic; @@ -110,6 +113,7 @@ namespace ICSharpCode.Data.Core.DatabaseDrivers.SQLServer 1,2,3,4"; private const string _getViews = @"SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='VIEW' AND TABLE_NAME<>'dtproperties' ORDER BY TABLE_SCHEMA, TABLE_NAME"; + private const string _getViewDefiningQuery = @"EXEC sp_helptext '{0}'"; private const string _getProcedures = "SELECT ROUTINE_NAME, ROUTINE_SCHEMA, ROUTINE_BODY, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE'"; private const string _getProcedureParameters = @"SELECT PARAMETER_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, PARAMETER_MODE, IS_RESULT FROM information_schema.PARAMETERS WHERE SPECIFIC_NAME = '{0}' AND SPECIFIC_SCHEMA = '{1}' AND SPECIFIC_CATALOG = '{2}'"; @@ -357,9 +361,8 @@ namespace ICSharpCode.Data.Core.DatabaseDrivers.SQLServer string schemaName = (string)dtViews.Rows[i]["TABLE_SCHEMA"]; string viewName = (string)dtViews.Rows[i]["TABLE_NAME"]; - View view = new View() { SchemaName = schemaName, TableName = viewName }; + View view = new View() { SchemaName = schemaName, TableName = viewName, Query = LoadViewQuery(sqlConnection, schemaName, viewName) }; LoadColumns(sqlConnection, view, TableType.View); - views.Add(view); } } @@ -367,6 +370,25 @@ namespace ICSharpCode.Data.Core.DatabaseDrivers.SQLServer return views; } + private string LoadViewQuery(SqlConnection sqlConnection, string schemaName, string tableName) + { + string definingQuery = string.Empty; + + using (SqlDataAdapter dataAdapter = + new SqlDataAdapter(string.Format(_getViewDefiningQuery, schemaName + "." + tableName), sqlConnection)) + { + DataTable dtQuery = new DataTable("Text"); + dataAdapter.Fill(dtQuery); + + for (int i = 0; i < dtQuery.Rows.Count; i++) + { + definingQuery += (string)dtQuery.Rows[i]["Text"]; + } + } + + return definingQuery; + } + public override DatabaseObjectsCollection LoadProcedures(IDatabase database) { DatabaseObjectsCollection procedures = new DatabaseObjectsCollection(database);