c# - 如何使用mvc中的entityframework从表中删除所有记录
问题描述
我想删除表的所有记录。我可以根据 id 删除,但我不想基于 id。我的 sql server 表名是[EnergyMonitoringDB].[dbo].[Energies]
如何删除它。
编码:
public string Delete_AllEnergyData() {
using (EnergyMonitoringDBEntities Obj = new EnergyMonitoringDBEntities())
{
Obj.Energies.RemoveRange(Obj.Energies);
Obj.SaveChanges();
return "Energy Data Deleted Successfully";
}
}
AngularJS 代码:
$scope.DeleteAll = function () {
$http({
method: "post",
url: "http://localhost:3523/Admin/Home/Delete_AllEnergyData",
datatype: "json",
data: JSON.stringify(Emp)
}).then(function (response) {
alert(response.data);
$scope.GetAllData();
})
};
html代码:
<input type="button" class="btn btn-danger" value="Delete All" ng-click="DeleteAll()" />
解决方案
Delete_AllEnergyData
没有任何参数。所以删除发送参数data: JSON.stringify(Emp)
到控制器如下:
$scope.DeleteAll = function () {
$http({
method: "post",
url: "http://localhost:3523/Admin/Home/Delete_AllEnergyData",
}).then(function (response) {
alert(response.data);
$scope.GetAllData();
})
};
推荐阅读
- android - 在 Android 中使用 OpenCV 进行预览和捕获的分辨率
- javascript - 基于条件 JavaScript 将对象添加到数组
- mysql - Docker 容器从 CLI 开始,但不是从 docker-compose.yml
- c# - GetLastInputInfo 不返回 dwTime
- c - 使用 spidev C 读取的数据与示波器测量结果不一致
- r - 根据主键添加列
- python - 在heroku上下载图像
- reactjs - 如何在 framer.motion 中的布局动画后摆脱条纹
- redis - 如何查看我的 redis 服务器每天执行多少命令?
- xcode - 有没有一种简单的方法来下载 Firebase 存储和数据库并在开发模式下使用这些快照,而不是调用 API?