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
pull/133/head
Christopher Jolly 3 years ago
parent 51037ec385
commit a9789216d2

@ -33,8 +33,8 @@ namespace EntityFrameworkCore.Jet.Data
}
}
public static DataAccessProviderType DefaultDataAccessProviderType { get; set; } = DataAccessProviderType.Odbc;
public static DataAccessProviderType DefaultDataAccessProviderType { get; set; } = DataAccessProviderType.Odbc;
// The SQL statement
//
// (SELECT COUNT(*) FROM MSysRelationships)
@ -57,17 +57,13 @@ namespace EntityFrameworkCore.Jet.Data
/// <summary>
/// The DUAL table or query
/// </summary>
public static string DUAL { get; set; } = DUALForAccdb;
public static string CustomDualTableName = "";
//MSysRelationships
//MSysAccessStorage
//#Dual
//(SELECT COUNT(*) FROM MSysAccessStorage)
/// <summary>
/// The dual table for accdb
/// </summary>
public const string DUALForMdb = "(SELECT COUNT(*) FROM MSysRelationships)";
/// <summary>
/// The dual table for accdb
/// </summary>
public const string DUALForAccdb = "(SELECT COUNT(*) FROM MSysAccessStorage)";
public static string DetectedDualTableName = "#Dual";
/// <summary>
/// Gets or sets a value indicating whether show SQL statements.

@ -224,7 +224,7 @@ namespace EntityFrameworkCore.Jet.Query.Sql.Internal
protected override void GeneratePseudoFromClause()
{
Sql.AppendLine()
.Append("FROM " + JetConfiguration.DUAL);
.Append("FROM " + "(SELECT COUNT(*) FROM `" + (string.IsNullOrEmpty(JetConfiguration.CustomDualTableName) ? JetConfiguration.DetectedDualTableName : JetConfiguration.CustomDualTableName) + "`)");
}
private void GenerateList<T>(

@ -105,7 +105,21 @@ namespace EntityFrameworkCore.Jet.Scaffolding.Internal
table.Database = databaseModel;
databaseModel.Tables.Add(table);
}
var tableNames = databaseModel.Tables.Select(t => t.Name).ToList();
if (tableNames.Contains("MSysAccessStorage"))
{
JetConfiguration.DetectedDualTableName = "MSysAccessStorage";
}
else if (tableNames.Contains("MSysRelationships"))
{
JetConfiguration.DetectedDualTableName = "MSysRelationships";
}
else if (tableNames.Contains("#Dual"))
{
JetConfiguration.DetectedDualTableName = "#Dual";
}
return databaseModel;
}
finally

Loading…
Cancel
Save