How to RESEED LocalDB Table using Entity Framework?

Mahdi Rashidi picture Mahdi Rashidi · Oct 2, 2014 · Viewed 10.2k times · Source

Is There any way to RESEED a LocalDB Table using EF?

I'd prefer not to use this SQL Command :

DBCC CHECKIDENT('TableName', RESEED, 0)

FYI : I'm using EF 6.1.

Thanks alot.

Answer

Darren Lamb picture Darren Lamb · Oct 10, 2014

I assume you're trying to reset the primary key on the table? If so, no there is no way in EF to do this.

As you stated, you would have to use a SQL command such as:

context.Database.ExecuteSqlCommand("DBCC CHECKIDENT('TableName', RESEED, 0)")

But I have to ask why you're trying to do this anyway? It shouldn't matter to you what value is in your primary key field.