In my Global.asax file, under my ApplicationStart() function I want to drop a table and recreate it cleanly when application starts. What is the best way to accomplish this so it is seamless every time i start my program? To get a better idea, I am keeping track of online users in a table, but when the application starts up again, obviously I would like to clear this table out. I need to drop and recreate the table because the identity seed won’t start over if i simply truncate it (I am using sql azure so i cannot run a db command to reset the seed). Also, if i did just truncate my table, would not resetting the seed be a bad practice? I’ve done this and im already at like id 1000, just after testing.
In my Global.asax file, under my ApplicationStart() function I want to drop a table
Share
You can do a normal SQL TRUNCATE command, using the ExecuteStoreCommand method.
Just like this
dbContext.ExecuteStoreCommand("TRUNCATE TABLE myTable");. Truncate deletes all records from table and resets the seed for auto id.