开发者

Reduce the size of a .MDF file when deleting data through Entity Framework

Is it possible to shrink manually the size of a .mdf file from the Entity Framework, or at least turn on the Auto Shrink option?

I've read in some places that it is not recommended, but that is a customer requirement (t开发者_StackOverflow社区o reduce the size of the file when data is deleted).


This is not an EF task/issue. It is a SQL Server maintenance task. You are correct when you shrink the files/database you leave your data fragmented. You would want to defragment immediately after.

I would not recommend making this a common behavior. Unless you are doing VERY large deletes the amount of space reclaimed is probably negligible. If you do need to shrink I would plan during low volume/down time and do the defragment as well.

I would inform your customer of this nature of this task and build a normal maintenance schedule to perform these types of DB activities. This would be a best practice approach.


Connect to database via standard SqlConnection and execute required operations. EF is not intended for this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜