I found this question: How to get the Schema name of a Table in Entity Framework? and built from there. My solution was to first create the extension methods in linked article and then modify the ObjectContext extension method to the following:
public static string GetTableAndSchema<T>(this ObjectContext context) where T : class
{
var sql = context.CreateObjectSet<T>.ToTraceString();
var startTrim = sql.LastIndexOf("FROM") + 5;
var initialTrim = sql.SubString(startTrim);
var endTrim = initialTrim.IndexOf("AS");
return sql.Substring(startTrim, endTrim).Replace("[","").Replace("]","");
}
This then allowed me to put the following in my GenericRepository:
public GenericRepository<TEntity> : IGenericRepository<TEntity> where TEntity : EntityBaseClass{
//REMOVED IRRELEVANT CODE
private MyContextType _context;
public virtual void AddBulk<IEnumerable<TEntity> toAdd, string connectionString, int batchSize)
{
using (SqlBulkCopy sbc = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.TableLock | SqlBulkCopyOptions.CheckContstraints | SqlBulkCopyOptions.KeepIdentity))
{
sbc.DestinationTableName = _context.GetTableAndSchema<TEntity>();
//DO THE REST OF SQL BULK COPY
}
}
}
This works perfectly for me and now allows me to have a SQL Bulk copy for every entity that exists in my context.