I use Linq to SQL for management and MS Access database.
To speed up batch modifications, I found it more efficient to directly execute queries using a datacontext, for example context.ExecutCommand("DELETE FROM [MyTable];"). For the sake of efficiency, I would like to make this an extension method, but I don't know how to get the table name from the context ...
I know that I can simply pass the table name as a string with hard code, for example:
public static void DeleteAll(this Table<TEntity> MyTable)
{
string tableName =
MyTable.Context.ExecuteCommand(string.Format("DELETE FROM [{0}];", tableName));
}
I have a way to get the table name, but you need help to get thsi to work. So far I:
var tableName = dc.MyTables.Context.GetTable(typeof(MyTable)).ElementType.Name;
But I canβt understand how to get the type of entities in MyTablesso that there is no hard code for the argument .GetTable()and make it suitable for any table that I went to.
Any response to C # or VB is ok. Thank.
EDIT
, , . - Context.MyTable.GetEntityType()... .