diff --git a/Source/LinqToDBDriver.cs b/Source/LinqToDBDriver.cs index f57e0ca..2a31715 100644 --- a/Source/LinqToDBDriver.cs +++ b/Source/LinqToDBDriver.cs @@ -220,52 +220,51 @@ public Exception TestConnection(ConnectionViewModel model) public override List GetSchemaAndBuildAssembly( IConnectionInfo cxInfo, AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName) { - List items = null; -try -{ - var gen = new SchemaAndCodeGenerator(cxInfo); - items = gen.GetItemsAndCode(nameSpace, typeName).ToList(); - var text = gen.Code.ToString(); - var syntaxTree = CSharpSyntaxTree.ParseText(text); - - var references = new List - { - MetadataReference.CreateFromFile(typeof(object). Assembly.Location), - MetadataReference.CreateFromFile(typeof(Enumerable). Assembly.Location), - MetadataReference.CreateFromFile(typeof(IDbConnection). Assembly.Location), - MetadataReference.CreateFromFile(typeof(DataConnection). Assembly.Location), - MetadataReference.CreateFromFile(typeof(LINQPadDataConnection).Assembly.Location), - }; - - references.AddRange(gen.References.Select(r => MetadataReference.CreateFromFile(r))); - - var compilation = CSharpCompilation.Create( - assemblyToBuild.Name, - syntaxTrees : new[] { syntaxTree }, - references : references, - options : new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); - - using (var stream = new FileStream(assemblyToBuild.CodeBase, FileMode.Create)) + try { - var result = compilation.Emit(stream); + var gen = new SchemaAndCodeGenerator(cxInfo); + var items = gen.GetItemsAndCode(nameSpace, typeName).ToList(); + var text = gen.Code.ToString(); + var syntaxTree = CSharpSyntaxTree.ParseText(text); - if (!result.Success) + var references = new List { - var failures = result.Diagnostics.Where(diagnostic => - diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error); + MetadataReference.CreateFromFile(typeof(object). Assembly.Location), + MetadataReference.CreateFromFile(typeof(Enumerable). Assembly.Location), + MetadataReference.CreateFromFile(typeof(IDbConnection). Assembly.Location), + MetadataReference.CreateFromFile(typeof(DataConnection). Assembly.Location), + MetadataReference.CreateFromFile(typeof(LINQPadDataConnection).Assembly.Location), + }; + + references.AddRange(gen.References.Select(r => MetadataReference.CreateFromFile(r))); + + var compilation = CSharpCompilation.Create( + assemblyToBuild.Name, + syntaxTrees : new[] { syntaxTree }, + references : references, + options : new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + + using (var stream = new FileStream(assemblyToBuild.CodeBase, FileMode.Create)) + { + var result = compilation.Emit(stream); + + if (!result.Success) + { + var failures = result.Diagnostics.Where(diagnostic => + diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error); - foreach (var diagnostic in failures) - throw new Exception(diagnostic.ToString()); + foreach (var diagnostic in failures) + throw new Exception(diagnostic.ToString()); + } } - } - -} -catch(Exception ex) -{ - MessageBox.Show($"{ex}\n{ex.StackTrace}"); -} - return items; + return items; + } + catch (Exception ex) + { + MessageBox.Show($"{ex}\n{ex.StackTrace}"); + throw; + } } public override ParameterDescriptor[] GetContextConstructorParameters(IConnectionInfo cxInfo) diff --git a/Source/SchemaAndCodeGenerator.cs b/Source/SchemaAndCodeGenerator.cs index 914ec50..9b249c5 100644 --- a/Source/SchemaAndCodeGenerator.cs +++ b/Source/SchemaAndCodeGenerator.cs @@ -205,7 +205,7 @@ from p in _schema.Procedures else { yield return new ExplorerItem( - GetUniqueName(_explorerNames, s.Key.SchemaName.IsNullOrEmpty() ? s.Key.IsDefaultSchema ? "(default)" : "empty" : s.Key.SchemaName), + s.Key.SchemaName.IsNullOrEmpty() ? s.Key.IsDefaultSchema ? "(default)" : "empty" : s.Key.SchemaName, ExplorerItemKind.Schema, ExplorerIcon.Schema) { @@ -380,15 +380,13 @@ void CodeProcedure(StringBuilder code, ProcedureSchema p, string sprocSqlName) code.AppendLine(" }"); } - HashSet _explorerNames = new HashSet(); - ExplorerItem GetColumnItem(ColumnSchema column) { var memberType = UseProviderSpecificTypes ? (column.ProviderSpecificType ?? column.MemberType) : column.MemberType; var sqlName = (string)_sqlBuilder.Convert(column.ColumnName, ConvertType.NameToQueryField); return new ExplorerItem( - GetUniqueName(_explorerNames, column.MemberName), + column.MemberName, ExplorerItemKind.Property, column.IsPrimaryKey ? ExplorerIcon.Key : ExplorerIcon.Column) { @@ -404,7 +402,7 @@ ExplorerItem GetProcedures(string header, ExplorerIcon icon, List(); - var items = new ExplorerItem(GetUniqueName(_explorerNames, header), ExplorerItemKind.Category, icon) + var items = new ExplorerItem(header, ExplorerItemKind.Category, icon) { Children = procedures .Select(p => @@ -425,7 +423,7 @@ ExplorerItem GetProcedures(string header, ExplorerIcon icon, List {res.ParameterType}"; } - var ret = new ExplorerItem(GetUniqueName(_explorerNames, memberName), ExplorerItemKind.QueryableObject, icon) + var ret = new ExplorerItem(memberName, ExplorerItemKind.QueryableObject, icon) { DragText = $"{p.MemberName}(" + p.Parameters @@ -439,7 +437,7 @@ ExplorerItem GetProcedures(string header, ExplorerIcon icon, List !pr.IsResult) .Select(pr => new ExplorerItem( - GetUniqueName(_explorerNames, $"{pr.ParameterName} ({pr.ParameterType})"), + $"{pr.ParameterName} ({pr.ParameterType})", ExplorerItemKind.Parameter, ExplorerIcon.Parameter)) .Union(p.ResultTable?.Columns.Select(GetColumnItem) ?? new ExplorerItem[0]) @@ -536,7 +534,7 @@ ExplorerItem GetTables(string header, ExplorerIcon icon, IEnumerable(); - var items = new ExplorerItem(GetUniqueName(_explorerNames, header), ExplorerItemKind.Category, icon) + var items = new ExplorerItem(header, ExplorerItemKind.Category, icon) { Children = tables .Select(t => @@ -555,7 +553,7 @@ ExplorerItem GetTables(string header, ExplorerIcon icon, IEnumerable", @@ -571,7 +569,7 @@ ExplorerItem GetTables(string header, ExplorerIcon icon, IEnumerable dic.ContainsKey(t))) { var entry = dic[table]; @@ -583,7 +581,7 @@ ExplorerItem GetTables(string header, ExplorerIcon icon, IEnumerable