Entity Framework(EF)测试DbContext.Database.ExecuteSqlCommand方法删除记录
Entity Framework(EF)测试DbContext.Database.ExecuteSqlCommand方法删除记录
若记录不存在,返回0:
C# Code:
using (var context = new UserDbContext())
{
context.Database.Log = Console.Write;
Console.WriteLine("Entity Framework(EF)测试DbContext.Database.ExecuteSqlCommand方法删除记录");
//使用SQL删除记录
string sql = "DELETE EFUsers WHERE ID=3";
int i = context.Database.ExecuteSqlCommand(sql);
Console.WriteLine("Save Changes Result:" + i.ToString());
Console.ReadLine();
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
using (var context = new UserDbContext())
{
context.Database.Log = Console.Write;
Console.WriteLine("Entity Framework(EF)测试DbContext.Database.ExecuteSqlCommand方法删除记录");
//使用SQL删除记录
string sql = "DELETE EFUsers WHERE ID=3";
int i = context.Database.ExecuteSqlCommand(sql);
Console.WriteLine("Save Changes Result:" + i.ToString());
Console.ReadLine();
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
若记录不存在,返回0:
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网