Skip to content

Commit a978921

Browse files
committed
Dual table: Auto detect the dual table name on model load. Use that table for any queries.
Also allow a custom override name to be set
1 parent 51037ec commit a978921

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

src/EFCore.Jet.Data/JetConfiguration.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public static object IntegerNullValue
3333
}
3434
}
3535

36-
public static DataAccessProviderType DefaultDataAccessProviderType { get; set; } = DataAccessProviderType.Odbc;
37-
36+
public static DataAccessProviderType DefaultDataAccessProviderType { get; set; } = DataAccessProviderType.Odbc;
37+
3838
// The SQL statement
3939
//
4040
// (SELECT COUNT(*) FROM MSysRelationships)
@@ -57,17 +57,13 @@ public static object IntegerNullValue
5757
/// <summary>
5858
/// The DUAL table or query
5959
/// </summary>
60-
public static string DUAL { get; set; } = DUALForAccdb;
60+
public static string CustomDualTableName = "";
61+
//MSysRelationships
62+
//MSysAccessStorage
63+
//#Dual
64+
//(SELECT COUNT(*) FROM MSysAccessStorage)
6165

62-
/// <summary>
63-
/// The dual table for accdb
64-
/// </summary>
65-
public const string DUALForMdb = "(SELECT COUNT(*) FROM MSysRelationships)";
66-
67-
/// <summary>
68-
/// The dual table for accdb
69-
/// </summary>
70-
public const string DUALForAccdb = "(SELECT COUNT(*) FROM MSysAccessStorage)";
66+
public static string DetectedDualTableName = "#Dual";
7167

7268
/// <summary>
7369
/// Gets or sets a value indicating whether show SQL statements.

src/EFCore.Jet/Query/Sql/Internal/JetQuerySqlGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private bool IsNonComposedSetOperation(SelectExpression selectExpression)
224224
protected override void GeneratePseudoFromClause()
225225
{
226226
Sql.AppendLine()
227-
.Append("FROM " + JetConfiguration.DUAL);
227+
.Append("FROM " + "(SELECT COUNT(*) FROM `" + (string.IsNullOrEmpty(JetConfiguration.CustomDualTableName) ? JetConfiguration.DetectedDualTableName : JetConfiguration.CustomDualTableName) + "`)");
228228
}
229229

230230
private void GenerateList<T>(

src/EFCore.Jet/Scaffolding/Internal/JetDatabaseModelFactory.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,21 @@ public override DatabaseModel Create(
105105
table.Database = databaseModel;
106106
databaseModel.Tables.Add(table);
107107
}
108-
108+
109+
var tableNames = databaseModel.Tables.Select(t => t.Name).ToList();
110+
if (tableNames.Contains("MSysAccessStorage"))
111+
{
112+
JetConfiguration.DetectedDualTableName = "MSysAccessStorage";
113+
}
114+
else if (tableNames.Contains("MSysRelationships"))
115+
{
116+
JetConfiguration.DetectedDualTableName = "MSysRelationships";
117+
}
118+
else if (tableNames.Contains("#Dual"))
119+
{
120+
JetConfiguration.DetectedDualTableName = "#Dual";
121+
}
122+
109123
return databaseModel;
110124
}
111125
finally

0 commit comments

Comments
 (0)