├── DynamicsTableAssociations ├── Table.cs ├── TableFieldAssociation.cs ├── DynamicsTableAssociations.csproj ├── LoadingForm.cs ├── TableHierarchy.cs ├── Program.cs ├── LoadingForm.Designer.cs ├── LoadingForm.resx ├── MainForm.resx ├── MainForm.cs └── MainForm.Designer.cs ├── README.md ├── DynamicsTableAssociations.sln ├── .gitattributes └── .gitignore /DynamicsTableAssociations/Table.cs: -------------------------------------------------------------------------------- 1 | namespace DynamicsTableAssociations 2 | { 3 | public class Table 4 | { 5 | public string Name { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /DynamicsTableAssociations/TableFieldAssociation.cs: -------------------------------------------------------------------------------- 1 | namespace DynamicsTableAssociations 2 | { 3 | public class TableFieldAssociation 4 | { 5 | public string ParentTableName { get; set; } 6 | public string ParentFieldName { get; set; } 7 | public string ChildTableName { get; set; } 8 | public string ChildFieldName { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /DynamicsTableAssociations/DynamicsTableAssociations.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WinExe 5 | netcoreapp3.1 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /DynamicsTableAssociations/LoadingForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | 9 | namespace DynamicsTableAssociations 10 | { 11 | public partial class LoadingForm : Form 12 | { 13 | public LoadingForm() 14 | { 15 | InitializeComponent(); 16 | this.CenterToParent(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DynamicsTableAssociations/TableHierarchy.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace DynamicsTableAssociations 4 | { 5 | public class TableHierarchy 6 | { 7 | public int Layer { get; set; } 8 | public string TableName { get; set; } 9 | public List ParentTableFieldAssociations { get; set; } 10 | 11 | public TableHierarchy() 12 | { 13 | ParentTableFieldAssociations = new List(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DynamicsTableAssociations/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace DynamicsTableAssociations 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.SetHighDpiMode(HighDpiMode.SystemAware); 18 | Application.EnableVisualStyles(); 19 | Application.SetCompatibleTextRenderingDefault(false); 20 | Application.Run(new MainForm()); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Microsoft Dynamics AX 2012 and Dynamics 365 for Finance and Operations Table Associations 2 | This project allows you to find the relations between tables in Microsoft Dynamics AX 2012 and Dynamics 365 for Finance and Operations. 3 | 4 | It utilizes the ERD information provided by Microsoft which I host at: https://alexdmeyer.com/ax2012erd. 5 | 6 | This solution can be used for both AX 2012 and D365FO as the table structures for both applications are similar. 7 | 8 | To run the application, you must have the .NET Core 3 Runtime Desktop installed. This can be found here: https://dotnet.microsoft.com/en-us/download/dotnet/3.1/runtime under the 'Run Desktop Apps' section. 9 | 10 | ## License 11 | MIT-licensed. 12 | -------------------------------------------------------------------------------- /DynamicsTableAssociations.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31729.503 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamicsTableAssociations", "DynamicsTableAssociations\DynamicsTableAssociations.csproj", "{B47707FB-F09A-4860-B69E-0239EDA30943}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {B47707FB-F09A-4860-B69E-0239EDA30943}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {B47707FB-F09A-4860-B69E-0239EDA30943}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {B47707FB-F09A-4860-B69E-0239EDA30943}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {B47707FB-F09A-4860-B69E-0239EDA30943}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {830F0558-2505-47BA-AA34-5EFD51433218} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /DynamicsTableAssociations/LoadingForm.Designer.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace DynamicsTableAssociations 3 | { 4 | partial class LoadingForm 5 | { 6 | /// 7 | /// Required designer variable. 8 | /// 9 | private System.ComponentModel.IContainer components = null; 10 | 11 | /// 12 | /// Clean up any resources being used. 13 | /// 14 | /// true if managed resources should be disposed; otherwise, false. 15 | protected override void Dispose(bool disposing) 16 | { 17 | if (disposing && (components != null)) 18 | { 19 | components.Dispose(); 20 | } 21 | base.Dispose(disposing); 22 | } 23 | 24 | #region Windows Form Designer generated code 25 | 26 | /// 27 | /// Required method for Designer support - do not modify 28 | /// the contents of this method with the code editor. 29 | /// 30 | private void InitializeComponent() 31 | { 32 | this.label1 = new System.Windows.Forms.Label(); 33 | this.SuspendLayout(); 34 | // 35 | // label1 36 | // 37 | this.label1.AutoSize = true; 38 | this.label1.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); 39 | this.label1.Location = new System.Drawing.Point(15, 17); 40 | this.label1.Name = "label1"; 41 | this.label1.Size = new System.Drawing.Size(293, 23); 42 | this.label1.TabIndex = 0; 43 | this.label1.Text = "Finding Table Relations ... Please Wait"; 44 | // 45 | // LoadingForm 46 | // 47 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); 48 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 49 | this.ClientSize = new System.Drawing.Size(320, 55); 50 | this.Controls.Add(this.label1); 51 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; 52 | this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); 53 | this.Name = "LoadingForm"; 54 | this.Text = "Analyzing ..."; 55 | this.ResumeLayout(false); 56 | this.PerformLayout(); 57 | 58 | } 59 | 60 | #endregion 61 | 62 | private System.Windows.Forms.Label label1; 63 | } 64 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /DynamicsTableAssociations/LoadingForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | text/microsoft-resx 50 | 51 | 52 | 2.0 53 | 54 | 55 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 56 | 57 | 58 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 59 | 60 | -------------------------------------------------------------------------------- /DynamicsTableAssociations/MainForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | text/microsoft-resx 50 | 51 | 52 | 2.0 53 | 54 | 55 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 56 | 57 | 58 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 59 | 60 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | -------------------------------------------------------------------------------- /DynamicsTableAssociations/MainForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text.Json; 7 | using System.Windows.Forms; 8 | 9 | namespace DynamicsTableAssociations 10 | { 11 | public partial class MainForm : Form 12 | { 13 | List tableList; 14 | List tableFieldAssociations; 15 | List> solutions; 16 | bool initialSearched; 17 | bool destSearched; 18 | string initTable; 19 | string destTable; 20 | 21 | int _SEARCH_LAYER; 22 | 23 | public MainForm() 24 | { 25 | InitializeComponent(); 26 | LoadFiles(); 27 | LoadTableLists(); 28 | ResizeListViewColumns(); 29 | 30 | initialSearched = false; 31 | destSearched = false; 32 | 33 | initTable = ""; 34 | destTable = ""; 35 | 36 | solutions = new List>(); 37 | 38 | _SEARCH_LAYER = 5; 39 | cb_SearchLayers.SelectedIndex = 0; 40 | } 41 | 42 | public void LoadFiles() 43 | { 44 | string tableFile = File.ReadAllText("tables.json"); 45 | string tableFieldAssociationFile = File.ReadAllText("tablefieldassociations.json"); 46 | 47 | tableList = (JsonSerializer.Deserialize>(tableFile)).OrderBy(t => t.Name).ToList(); 48 | tableFieldAssociations = JsonSerializer.Deserialize>(tableFieldAssociationFile); 49 | } 50 | 51 | public void LoadTableLists() 52 | { 53 | foreach(var table in tableList) 54 | { 55 | ListViewItem initialItem = new ListViewItem(new[] { table.Name }); 56 | ListViewItem destItem = new ListViewItem(new[] { table.Name }); 57 | 58 | lv_initial.Items.Add(initialItem); 59 | lv_dest.Items.Add(destItem); 60 | } 61 | } 62 | 63 | private void ResizeListViewColumns() 64 | { 65 | foreach (ColumnHeader column in lv_initial.Columns) 66 | { 67 | column.Width = -2; 68 | } 69 | 70 | foreach (ColumnHeader column in lv_dest.Columns) 71 | { 72 | column.Width = -2; 73 | } 74 | } 75 | 76 | private void tbInitial_TextChanged(object sender, EventArgs e) 77 | { 78 | if(tb_initial.Text.Length >= 3) 79 | { 80 | lv_initial.Items.Clear(); 81 | IEnumerable
searchedTables = tableList.Where(t => t.Name.ToLower().Contains(tb_initial.Text.ToLower())); 82 | foreach(var table in searchedTables) 83 | { 84 | ListViewItem initialItem = new ListViewItem(new[] { table.Name }); 85 | lv_initial.Items.Add(initialItem); 86 | } 87 | initialSearched = true; 88 | ResizeListViewColumns(); 89 | } 90 | else 91 | { 92 | if (initialSearched) 93 | { 94 | lv_initial.Items.Clear(); 95 | foreach (var table in tableList) 96 | { 97 | ListViewItem initialItem = new ListViewItem(new[] { table.Name }); 98 | lv_initial.Items.Add(initialItem); 99 | } 100 | initialSearched = false; 101 | ResizeListViewColumns(); 102 | } 103 | } 104 | } 105 | 106 | private void tbDest_TextChanged(object sender, EventArgs e) 107 | { 108 | if (tb_dest.Text.Length >= 3) 109 | { 110 | lv_dest.Items.Clear(); 111 | IEnumerable
searchedTables = tableList.Where(t => t.Name.ToLower().Contains(tb_dest.Text.ToLower())); 112 | foreach (var table in searchedTables) 113 | { 114 | ListViewItem destItem = new ListViewItem(new[] { table.Name }); 115 | lv_dest.Items.Add(destItem); 116 | } 117 | destSearched = true; 118 | ResizeListViewColumns(); 119 | } 120 | else 121 | { 122 | if (destSearched) 123 | { 124 | lv_dest.Items.Clear(); 125 | foreach (var table in tableList) 126 | { 127 | ListViewItem destItem = new ListViewItem(new[] { table.Name }); 128 | lv_dest.Items.Add(destItem); 129 | } 130 | destSearched = false; 131 | ResizeListViewColumns(); 132 | } 133 | } 134 | } 135 | 136 | private void lvInitial_SelectedIndexChanged(object sender, EventArgs e) 137 | { 138 | if (lv_initial.SelectedItems.Count > 0 && lv_dest.SelectedItems.Count > 0) 139 | btn_analyze.Enabled = true; 140 | } 141 | 142 | private void lvDest_SelectedIndexChanged(object sender, EventArgs e) 143 | { 144 | if (lv_initial.SelectedItems.Count > 0 && lv_dest.SelectedItems.Count > 0) 145 | btn_analyze.Enabled = true; 146 | } 147 | 148 | private void btnAnalyze_Click(object sender, EventArgs e) 149 | { 150 | LoadingForm lf = new LoadingForm(); 151 | try 152 | { 153 | lf.Show(); 154 | lf.Refresh(); 155 | 156 | lv_output.Items.Clear(); 157 | solutions = new List>(); 158 | initTable = lv_initial.SelectedItems[0].Text; 159 | destTable = lv_dest.SelectedItems[0].Text; 160 | if (initTable == destTable) 161 | { 162 | ListViewItem noItems = new ListViewItem(new[] { "Same Table", "Selected For", "Initial &", "Destination" }); 163 | lv_output.Items.Add(noItems); 164 | } 165 | else 166 | { 167 | TableHierarchy th = new TableHierarchy() 168 | { 169 | TableName = initTable, 170 | Layer = 1 171 | }; 172 | 173 | int searchLayer = int.Parse(cb_SearchLayers.SelectedItem.ToString()); 174 | _SEARCH_LAYER = searchLayer + 1; 175 | 176 | FindTableAssociations(th); 177 | if (solutions.Any()) 178 | { 179 | int i = 2; 180 | while (i <= _SEARCH_LAYER) 181 | { 182 | List> sortedSolutions = solutions.Where(l => l.Count() == i).OrderBy(x => x.First().ChildTableName).ToList(); 183 | if (sortedSolutions.Any()) 184 | { 185 | foreach (var solution in sortedSolutions) 186 | { 187 | foreach (var entry in solution) 188 | { 189 | ListViewItem item = new ListViewItem(new[] { entry.ParentTableName, entry.ParentFieldName, entry.ChildTableName, entry.ChildFieldName }); 190 | lv_output.Items.Add(item); 191 | } 192 | 193 | ListViewItem seperator = new ListViewItem(new[] { "--", "--", "--", "--" }); 194 | lv_output.Items.Add(seperator); 195 | } 196 | } 197 | i++; 198 | } 199 | } 200 | else 201 | { 202 | ListViewItem noItems = new ListViewItem(new[] { "No", "Solution", "Found", "!!!" }); 203 | lv_output.Items.Add(noItems); 204 | } 205 | } 206 | 207 | lf.Close(); 208 | } 209 | catch(Exception ex) 210 | { 211 | lf.Close(); 212 | MessageBox.Show(ex.Message + " - \n" + ex.StackTrace, "Error Analyzing Table Relations", MessageBoxButtons.OK, MessageBoxIcon.Error); 213 | } 214 | } 215 | 216 | private void FindTableAssociations(TableHierarchy tableHierarchy) 217 | { 218 | //Remove layers from ParentTableFieldAssociations that did not find a solution 219 | while (tableHierarchy.ParentTableFieldAssociations.Count >= tableHierarchy.Layer) 220 | tableHierarchy.ParentTableFieldAssociations.RemoveAt(tableHierarchy.ParentTableFieldAssociations.Count - 1); 221 | 222 | bool foundSolution = false; 223 | if(tableHierarchy.Layer < _SEARCH_LAYER) 224 | { 225 | //Find all child tables that have relations to parent 226 | var childTableFields = tableFieldAssociations.Where(ta => string.Equals(ta.ParentTableName, tableHierarchy.TableName, StringComparison.CurrentCultureIgnoreCase)).ToList(); 227 | foreach (var childTableFieldAssociation in childTableFields) 228 | { 229 | //Remove layers from ParentTableFieldAssociations that did not find a solution 230 | while (tableHierarchy.ParentTableFieldAssociations.Count >= tableHierarchy.Layer) 231 | tableHierarchy.ParentTableFieldAssociations.RemoveAt(tableHierarchy.ParentTableFieldAssociations.Count - 1); 232 | 233 | if (string.Equals(childTableFieldAssociation.ChildTableName, destTable, StringComparison.CurrentCultureIgnoreCase)) 234 | { 235 | List tableFields = new List(); 236 | tableFields.AddRange(tableHierarchy.ParentTableFieldAssociations); 237 | tableFields.Add(childTableFieldAssociation); 238 | solutions.Add(tableFields); 239 | foundSolution = true; 240 | } 241 | 242 | if (!foundSolution) 243 | { 244 | //Create a new object to pass to next iteration 245 | TableHierarchy childTableHierarchy = new TableHierarchy() 246 | { 247 | TableName = childTableFieldAssociation.ChildTableName, 248 | Layer = (tableHierarchy.Layer + 1), 249 | ParentTableFieldAssociations = tableHierarchy.ParentTableFieldAssociations 250 | }; 251 | 252 | if (string.Equals(childTableFieldAssociation.ParentTableName, initTable, StringComparison.CurrentCultureIgnoreCase)) 253 | childTableHierarchy.ParentTableFieldAssociations = new List(); 254 | 255 | //Logic to stop cycles where a->b, b->a or a->b, b->c, c->a 256 | if(!childTableHierarchy.ParentTableFieldAssociations.Any(pfa => string.Equals(pfa.ParentTableName, childTableHierarchy.TableName, StringComparison.CurrentCultureIgnoreCase))) 257 | { 258 | childTableHierarchy.ParentTableFieldAssociations.Add(childTableFieldAssociation); 259 | FindTableAssociations(childTableHierarchy); 260 | } 261 | } 262 | else 263 | { 264 | continue; 265 | } 266 | } 267 | } 268 | } 269 | } 270 | } 271 | -------------------------------------------------------------------------------- /DynamicsTableAssociations/MainForm.Designer.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace DynamicsTableAssociations 3 | { 4 | partial class MainForm 5 | { 6 | /// 7 | /// Required designer variable. 8 | /// 9 | private System.ComponentModel.IContainer components = null; 10 | 11 | /// 12 | /// Clean up any resources being used. 13 | /// 14 | /// true if managed resources should be disposed; otherwise, false. 15 | protected override void Dispose(bool disposing) 16 | { 17 | if (disposing && (components != null)) 18 | { 19 | components.Dispose(); 20 | } 21 | base.Dispose(disposing); 22 | } 23 | 24 | #region Windows Form Designer generated code 25 | 26 | /// 27 | /// Required method for Designer support - do not modify 28 | /// the contents of this method with the code editor. 29 | /// 30 | private void InitializeComponent() 31 | { 32 | this.label1 = new System.Windows.Forms.Label(); 33 | this.tb_initial = new System.Windows.Forms.TextBox(); 34 | this.label2 = new System.Windows.Forms.Label(); 35 | this.tb_dest = new System.Windows.Forms.TextBox(); 36 | this.label3 = new System.Windows.Forms.Label(); 37 | this.label4 = new System.Windows.Forms.Label(); 38 | this.btn_analyze = new System.Windows.Forms.Button(); 39 | this.lv_initial = new System.Windows.Forms.ListView(); 40 | this.lvInitialName = new System.Windows.Forms.ColumnHeader(); 41 | this.lv_dest = new System.Windows.Forms.ListView(); 42 | this.lvDestName = new System.Windows.Forms.ColumnHeader(); 43 | this.lv_output = new System.Windows.Forms.ListView(); 44 | this.ParentTable = new System.Windows.Forms.ColumnHeader(); 45 | this.ParentColumn = new System.Windows.Forms.ColumnHeader(); 46 | this.ChildTable = new System.Windows.Forms.ColumnHeader(); 47 | this.ChildColumn = new System.Windows.Forms.ColumnHeader(); 48 | this.cb_SearchLayers = new System.Windows.Forms.ComboBox(); 49 | this.label5 = new System.Windows.Forms.Label(); 50 | this.SuspendLayout(); 51 | // 52 | // label1 53 | // 54 | this.label1.AutoSize = true; 55 | this.label1.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); 56 | this.label1.Location = new System.Drawing.Point(14, 77); 57 | this.label1.Name = "label1"; 58 | this.label1.Size = new System.Drawing.Size(70, 23); 59 | this.label1.TabIndex = 0; 60 | this.label1.Text = "Search :"; 61 | // 62 | // tb_initial 63 | // 64 | this.tb_initial.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); 65 | this.tb_initial.Location = new System.Drawing.Point(82, 73); 66 | this.tb_initial.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); 67 | this.tb_initial.Name = "tb_initial"; 68 | this.tb_initial.Size = new System.Drawing.Size(361, 29); 69 | this.tb_initial.TabIndex = 1; 70 | this.tb_initial.TextChanged += new System.EventHandler(this.tbInitial_TextChanged); 71 | // 72 | // label2 73 | // 74 | this.label2.AutoSize = true; 75 | this.label2.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); 76 | this.label2.Location = new System.Drawing.Point(507, 77); 77 | this.label2.Name = "label2"; 78 | this.label2.Size = new System.Drawing.Size(70, 23); 79 | this.label2.TabIndex = 2; 80 | this.label2.Text = "Search :"; 81 | // 82 | // tb_dest 83 | // 84 | this.tb_dest.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); 85 | this.tb_dest.Location = new System.Drawing.Point(576, 73); 86 | this.tb_dest.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); 87 | this.tb_dest.Name = "tb_dest"; 88 | this.tb_dest.Size = new System.Drawing.Size(371, 29); 89 | this.tb_dest.TabIndex = 3; 90 | this.tb_dest.TextChanged += new System.EventHandler(this.tbDest_TextChanged); 91 | // 92 | // label3 93 | // 94 | this.label3.AutoSize = true; 95 | this.label3.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); 96 | this.label3.Location = new System.Drawing.Point(15, 17); 97 | this.label3.Name = "label3"; 98 | this.label3.Size = new System.Drawing.Size(110, 28); 99 | this.label3.TabIndex = 6; 100 | this.label3.Text = "Initial Table"; 101 | // 102 | // label4 103 | // 104 | this.label4.AutoSize = true; 105 | this.label4.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); 106 | this.label4.Location = new System.Drawing.Point(507, 24); 107 | this.label4.Name = "label4"; 108 | this.label4.Size = new System.Drawing.Size(162, 28); 109 | this.label4.TabIndex = 7; 110 | this.label4.Text = "Destination Table"; 111 | // 112 | // btn_analyze 113 | // 114 | this.btn_analyze.Enabled = false; 115 | this.btn_analyze.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); 116 | this.btn_analyze.Location = new System.Drawing.Point(719, 479); 117 | this.btn_analyze.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); 118 | this.btn_analyze.Name = "btn_analyze"; 119 | this.btn_analyze.Size = new System.Drawing.Size(229, 40); 120 | this.btn_analyze.TabIndex = 9; 121 | this.btn_analyze.Text = "Find Associations"; 122 | this.btn_analyze.UseVisualStyleBackColor = true; 123 | this.btn_analyze.Click += new System.EventHandler(this.btnAnalyze_Click); 124 | // 125 | // lv_initial 126 | // 127 | this.lv_initial.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 128 | this.lvInitialName}); 129 | this.lv_initial.FullRowSelect = true; 130 | this.lv_initial.GridLines = true; 131 | this.lv_initial.HideSelection = false; 132 | this.lv_initial.Location = new System.Drawing.Point(15, 115); 133 | this.lv_initial.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); 134 | this.lv_initial.MultiSelect = false; 135 | this.lv_initial.Name = "lv_initial"; 136 | this.lv_initial.Size = new System.Drawing.Size(428, 355); 137 | this.lv_initial.TabIndex = 10; 138 | this.lv_initial.UseCompatibleStateImageBehavior = false; 139 | this.lv_initial.View = System.Windows.Forms.View.Details; 140 | this.lv_initial.SelectedIndexChanged += new System.EventHandler(this.lvInitial_SelectedIndexChanged); 141 | // 142 | // lvInitialName 143 | // 144 | this.lvInitialName.Text = "Name"; 145 | // 146 | // lv_dest 147 | // 148 | this.lv_dest.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 149 | this.lvDestName}); 150 | this.lv_dest.FullRowSelect = true; 151 | this.lv_dest.GridLines = true; 152 | this.lv_dest.HideSelection = false; 153 | this.lv_dest.Location = new System.Drawing.Point(519, 115); 154 | this.lv_dest.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); 155 | this.lv_dest.MultiSelect = false; 156 | this.lv_dest.Name = "lv_dest"; 157 | this.lv_dest.Size = new System.Drawing.Size(428, 355); 158 | this.lv_dest.TabIndex = 11; 159 | this.lv_dest.UseCompatibleStateImageBehavior = false; 160 | this.lv_dest.View = System.Windows.Forms.View.Details; 161 | this.lv_dest.SelectedIndexChanged += new System.EventHandler(this.lvDest_SelectedIndexChanged); 162 | // 163 | // lvDestName 164 | // 165 | this.lvDestName.Text = "Name"; 166 | // 167 | // lv_output 168 | // 169 | this.lv_output.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 170 | this.ParentTable, 171 | this.ParentColumn, 172 | this.ChildTable, 173 | this.ChildColumn}); 174 | this.lv_output.FullRowSelect = true; 175 | this.lv_output.GridLines = true; 176 | this.lv_output.HideSelection = false; 177 | this.lv_output.Location = new System.Drawing.Point(15, 548); 178 | this.lv_output.Name = "lv_output"; 179 | this.lv_output.Size = new System.Drawing.Size(932, 384); 180 | this.lv_output.TabIndex = 12; 181 | this.lv_output.UseCompatibleStateImageBehavior = false; 182 | this.lv_output.View = System.Windows.Forms.View.Details; 183 | // 184 | // ParentTable 185 | // 186 | this.ParentTable.Text = "Parent Table"; 187 | this.ParentTable.Width = 200; 188 | // 189 | // ParentColumn 190 | // 191 | this.ParentColumn.Text = "Parent Column"; 192 | this.ParentColumn.Width = 200; 193 | // 194 | // ChildTable 195 | // 196 | this.ChildTable.Text = "Child Table"; 197 | this.ChildTable.Width = 200; 198 | // 199 | // ChildColumn 200 | // 201 | this.ChildColumn.Text = "Child Column"; 202 | this.ChildColumn.Width = 200; 203 | // 204 | // cb_SearchLayers 205 | // 206 | this.cb_SearchLayers.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 207 | this.cb_SearchLayers.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); 208 | this.cb_SearchLayers.FormattingEnabled = true; 209 | this.cb_SearchLayers.Items.AddRange(new object[] { 210 | "1", 211 | "2", 212 | "3", 213 | "4", 214 | "5"}); 215 | this.cb_SearchLayers.Location = new System.Drawing.Point(252, 489); 216 | this.cb_SearchLayers.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); 217 | this.cb_SearchLayers.Name = "cb_SearchLayers"; 218 | this.cb_SearchLayers.Size = new System.Drawing.Size(191, 29); 219 | this.cb_SearchLayers.TabIndex = 13; 220 | // 221 | // label5 222 | // 223 | this.label5.AutoSize = true; 224 | this.label5.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); 225 | this.label5.Location = new System.Drawing.Point(15, 489); 226 | this.label5.Name = "label5"; 227 | this.label5.Size = new System.Drawing.Size(231, 23); 228 | this.label5.TabIndex = 14; 229 | this.label5.Text = "Number of Layers to Search :"; 230 | // 231 | // MainForm 232 | // 233 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); 234 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 235 | this.ClientSize = new System.Drawing.Size(961, 945); 236 | this.Controls.Add(this.label5); 237 | this.Controls.Add(this.cb_SearchLayers); 238 | this.Controls.Add(this.lv_output); 239 | this.Controls.Add(this.lv_dest); 240 | this.Controls.Add(this.lv_initial); 241 | this.Controls.Add(this.btn_analyze); 242 | this.Controls.Add(this.label4); 243 | this.Controls.Add(this.label3); 244 | this.Controls.Add(this.tb_dest); 245 | this.Controls.Add(this.label2); 246 | this.Controls.Add(this.tb_initial); 247 | this.Controls.Add(this.label1); 248 | this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); 249 | this.Name = "MainForm"; 250 | this.Text = "Dynamics AX / 365FO Table Associations"; 251 | this.ResumeLayout(false); 252 | this.PerformLayout(); 253 | 254 | } 255 | 256 | #endregion 257 | 258 | private System.Windows.Forms.Label label1; 259 | private System.Windows.Forms.TextBox tb_initial; 260 | private System.Windows.Forms.Label label2; 261 | private System.Windows.Forms.TextBox tb_dest; 262 | private System.Windows.Forms.Label label3; 263 | private System.Windows.Forms.Label label4; 264 | private System.Windows.Forms.Button btn_analyze; 265 | private System.Windows.Forms.ListView lv_initial; 266 | private System.Windows.Forms.ColumnHeader lvInitialName; 267 | private System.Windows.Forms.ListView lv_dest; 268 | private System.Windows.Forms.ColumnHeader lvDestName; 269 | private System.Windows.Forms.ListView lv_output; 270 | private System.Windows.Forms.ColumnHeader ParentTable; 271 | private System.Windows.Forms.ColumnHeader ParentColumn; 272 | private System.Windows.Forms.ColumnHeader ChildTable; 273 | private System.Windows.Forms.ColumnHeader ChildColumn; 274 | private System.Windows.Forms.ComboBox cb_SearchLayers; 275 | private System.Windows.Forms.Label label5; 276 | } 277 | } 278 | 279 | --------------------------------------------------------------------------------