I need to issue a Truncate Table instead of deleting individual records.
I can easily do that with TypedListDAO and an ActionQuery.
However, I thought I would make an extension to do this and that code is below.
Few questions:
1) Seems this would be better if I could call the extension on a collection entity - but I have no way of getting to the entity.LLBLGenProEntityName, so I had to put this extension on an entity. Is there a way to do this?
2) Is my use of the DQE and such correct below?
public static void TruncateTable(this IEntityCore entity)
{
TypedListDAO typedListDAO = new TypedListDAO();
IFieldPersistenceInfo[] persitanceInfo = PersistenceInfoProviderSingleton.GetInstance().GetAllFieldPersistenceInfos(entity.LLBLGenProEntityName);
if (persitanceInfo == null || persitanceInfo.Length == 0)
throw new Exception("Invalid entity for TruncateTable");
var dqe = new SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine();
string tableToTruncate = dqe.Creator.CreateObjectName(persitanceInfo[0]);
// ACTION QUERY
// create an action query using a connection created by our DbUtils...
IActionQuery query2 = new ActionQuery(new SqlCommand("truncate table " + tableToTruncate));
// execute the query
typedListDAO.ExecuteActionQuery(query2, null);
}