日期:2014-05-16 浏览次数:20375 次
我采用Database First,用Sql很容易就可以做到对一个表进行压缩。如以下:
CREATE TABLE [dbo].[Entities]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](max) NULL, Primary Key Clustered ([Id] ASC) WITH (DATA_COMPRESSION=PAGE) );
public class CreateDatabaseWithCompressionIfNotExists : CreateDatabaseIfNotExists<MyContext> { protected override void Seed(testEntities context) { var cmd = new SqlCommand(); var con = new SqlConnection(context.Database.Connection.ConnectionString); con.Open(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = "alter table entities rebuild with (data_compression=page);"; cmd.ExecuteNonQuery(); } }Main函数里的调用 :
private static void Main(string[] args) { Database.SetInitializer(new CreateDatabaseWithCompressionIfNotExists()); //这里就会调用实现对表的修改了。 var test = new testEntities(); test.Entities.Add(new Model.Entity()); test.SaveChanges(); }