using(var context = new SampleContext())
{
var commandText = "INSERT Categories (CategoryName) VALUES (@CategoryName)";
var name = new SqlParameter("@CategoryName", "Test");
context.Database.ExecuteSqlCommand(commandText, name);
}
- or execute sql when migration
public partial class UpdateDbOptions: Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
var sp = @"ALTER DATABASE [mydatabase]
SET CHANGE_TRACKING = ON
(CHANGE_RETENTION = 2 DAYS, AUTO_CLEANUP = ON)";
migrationBuilder.Sql(sp);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…