标签:from for console region 操作 部分 man script span
1 string sql = @"INSERT INTO region(RegionID, RegionDescription) VALUES(@regionId, @regionDescription)"; 2 var result = context.Database.ExecuteSqlCommand(sql, 3 new MySqlParameter("@regionId", 5), 4 new MySqlParameter("@regionDescription", "Center")); 5 if (result >= 1) 6 { 7 Console.WriteLine("插入新数据成功"); 8 } 9 else 10 { 11 Console.WriteLine("插入数据失败"); 12 } 13 string sql = @"DELETE FROM region WHERE RegionID = @regionId"; 14 var result = context.Database.ExecuteSqlCommand(sql, 15 new MySqlParameter("@regionId", 5)); 16 if (result >= 1) 17 { 18 Console.WriteLine("删除数据成功"); 19 } 20 else 21 { 22 Console.WriteLine("删除数据失败"); 23 }
1 string sql = @"SELECT RegionID, RegionDescription FROM region"; 2 var result = context.Database.SqlQuery<Region>(sql); 3 foreach (Region region in result) 4 { 5 Console.WriteLine("Region = {0}, RegionDescription = {1}", 6 region.RegionId, region.RegionDescription); 7 }
1 var result = context.Database.SqlQuery<Region>(sql);
也可以使用ExecuteSqlCommand()和SqlQuery<T>()执行存储过程,只需要将示例中的SQL语句换成存储过程的名称即可
标签:from for console region 操作 部分 man script span
原文地址:http://www.cnblogs.com/hebutyll/p/6870044.html