标签:entity framework database first 表压缩 code first表压缩 ef 表压缩
我采用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();
}Entity Framework Database/Code First实现对表进行压缩配置
标签:entity framework database first 表压缩 code first表压缩 ef 表压缩
原文地址:http://blog.csdn.net/kmguo/article/details/24777581