On a bit further inspection I can see that there is code commented out in
Nop.Data.DbContextExtensions.GetTableName<T>(this IDbContext context) where T : BaseEntity
which looks like it grabs the schema name. I had problems uninstalling my plugin because the schema name was missing in the table name.
To fix it I created my own extension class and copied that method into my own extension class. Then I simply uncommented that part and changed it to use the appropriate variable to look for the schema name and now it works.
Here is the extension class if someone is interested:
using Nop.Core;
using Nop.Data;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Infrastructure;
using System.Linq;
namespace MyAwesomeNamespace.Extensions
{
public static class DbContextExtensions
{
/// <summary>
/// Get table name of entity
/// </summary>
/// <typeparam name="T">Entity type</typeparam>
/// <param name="context">Context</param>
/// <returns>Table name with the schema name and a dot appended.</returns>
public static string GetTableNameWithSchema<T>(this IDbContext context) where T : BaseEntity
{
//var tableName = typeof(T).Name;
//return tableName;
//this code works only with Entity Framework.
//If you want to support other database, then use the code above (commented)
var adapter = ((IObjectContextAdapter)context).ObjectContext;
var storageModel = (StoreItemCollection)adapter.MetadataWorkspace.GetItemCollection(DataSpace.SSpace);
var containers = storageModel.GetItems<EntityContainer>();
var entitySetBase = containers.SelectMany(c => c.BaseEntitySets.Where(bes => bes.Name == typeof(T).Name)).First();
// Here are variables that will hold table and schema name
string tableName = entitySetBase.MetadataProperties.First(p => p.Name == "Table").Value.ToString();
string schemaName = entitySetBase.MetadataProperties.First(p => p.Name == "Schema").Value.ToString();
return schemaName + "." + tableName;
}
}
}
I would absolutely LOVE for a developer to look at this and either "approve" it or tell me what is wrong with it and potentially tell me what COULD go wrong.
For now I have only tested it by installing a plugin without the changes and then uninstall it. Then I get the error that it cannot find the tablename. The reason for that is because the schema name is missing.
Then I add the extension and it works fine with uninstalling the plugin.
Cheers!