22using Diol . Share . Features . EntityFrameworks ;
33using Diol . Wpf . Core . Services ;
44using Prism . Events ;
5+ using System . Collections . Generic ;
56
67namespace Diol . Wpf . Core . Features . EntityFrameworks
78{
@@ -13,6 +14,8 @@ public class EntityFrameworkService
1314 private readonly IStore < EntityFrameworkModel > store ;
1415 private readonly IEventAggregator eventAggregator ;
1516
17+ private readonly Dictionary < string , int > multipleQueries = new Dictionary < string , int > ( ) ;
18+
1619 /// <summary>
1720 /// Initializes a new instance of the <see cref="EntityFrameworkService"/> class.
1821 /// </summary>
@@ -33,6 +36,11 @@ public EntityFrameworkService(
3336 /// <returns>The Entity Framework model item with the specified key, or the default value if not found.</returns>
3437 public EntityFrameworkModel GetItemOrDefault ( string key )
3538 {
39+ if ( this . multipleQueries . Count >= 128 )
40+ {
41+ this . multipleQueries . Clear ( ) ;
42+ }
43+
3644 return this . store . GetItemOrDefault ( key ) ;
3745 }
3846
@@ -69,6 +77,44 @@ public void Update(ConnectionOpeningDto dto)
6977 /// <param name="dto">The command executing DTO.</param>
7078 public void Update ( CommandExecutingDto dto )
7179 {
80+ if ( ! this . multipleQueries . ContainsKey ( dto . CorrelationId ) )
81+ {
82+ this . multipleQueries . Add ( dto . CorrelationId , 0 ) ;
83+ }
84+ else
85+ {
86+ this . multipleQueries [ dto . CorrelationId ] ++ ;
87+ var relationId = this . multipleQueries [ dto . CorrelationId ] ;
88+
89+ var correlationId = $ "{ dto . CorrelationId } _{ relationId } ";
90+
91+ var prevItem = this . store
92+ . GetItemOrDefault ( dto . CorrelationId ) ;
93+
94+ if ( prevItem == null )
95+ {
96+ return ;
97+ }
98+
99+ var processId = prevItem . ConnectionOpening . ProcessId ;
100+ var processName = prevItem . ConnectionOpening . ProcessName ;
101+ var server = prevItem . ConnectionOpening . Server ;
102+ var databaseName = prevItem . ConnectionOpening . Database ;
103+
104+ var createItem = new ConnectionOpeningDto ( )
105+ {
106+ CorrelationId = correlationId ,
107+ ProcessId = processId ,
108+ ProcessName = processName ,
109+ Server = server ,
110+ Database = databaseName ,
111+ } ;
112+
113+ this . Update ( createItem ) ;
114+
115+ dto . CorrelationId = correlationId ;
116+ }
117+
72118 var item = this . store
73119 . GetItemOrDefault ( dto . CorrelationId ) ;
74120
@@ -92,6 +138,13 @@ public void Update(CommandExecutingDto dto)
92138 /// <param name="dto">The command executed DTO.</param>
93139 public void Update ( CommandExecutedDto dto )
94140 {
141+ if ( this . multipleQueries . ContainsKey ( dto . CorrelationId ) )
142+ {
143+ var relationId = this . multipleQueries [ dto . CorrelationId ] ;
144+ var correlationId = relationId > 0 ? $ "{ dto . CorrelationId } _{ relationId } " : dto . CorrelationId ;
145+ dto . CorrelationId = correlationId ;
146+ }
147+
95148 var item = this . store
96149 . GetItemOrDefault ( dto . CorrelationId ) ;
97150
0 commit comments