javascript - 如果存在 DataContext,则该方法不会启动
问题描述
再会
我正在尝试硬删除软删除的记录,我有一个方法Task PermanantlyDeleteDeal(GetDealInput input)
当我调用该方法时它不会进入。
由于样板 0.9.6 不是硬删除,我现在使用Database>DataContext.cs
类来执行硬删除
这是我的 DataContext 类
public class DataContext : DbContext
{
public virtual DbSet<Deal> Deal{ get; set; }
public DataContext()
: base("Default")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
}}
这是您调用该方法的javaScript上的函数
function DeleteLead(btnCaller) {
abp.message.confirm('Lead will be deleted.', 'Are you sure?', function (isConfirmed) {
if (isConfirmed) {
var button = $(btnCaller);
var proposalId = button.data('content');
var proposalObject = Object({
Id: proposalId
});
abp.ui.setBusy();
_leadService.permanantlyDeleteLead(proposalObject).done(function (result) {
abp.notify.success('Successfully deleted a proposal', 'Quotation deleted');
Refresh();
}).always(function () {
abp.ui.clearBusy();
});
}
});
}
这是永久删除评论
public async Task PermanantlyDeleteDeal(GetDealInput input)
{
UserFriendlyException ufex = null;
try
{
DataContext db = new DataContext();
using (Repository.Repository<Deal> repo = new Repository.Repository<Deal>(db))
{
using (Repository.Repository<DealComment> dealCommentRepo = new Repository.Repository<DealComment>(db))
{
using (Repository.Repository<Proposal> proposalRepo = new Repository.Repository<Proposal>(db))
{
using (Repository.Repository<Quotation> quotationRepo = new Repository.Repository<Quotation>(db))
{
Deal deal = repo.GetById(input.Id);
List<DealComment> listOfDealComments = dealCommentRepo.GetAll().Where(dc => dc.DealId == deal.Id).ToList();
List<Proposal> listOfProposals = proposalRepo.GetAll().Where(x => x.DealId == deal.Id).ToList();
List<Quotation> listOfQuotations = quotationRepo.GetAll().Where(x => x.DealId == deal.Id).ToList();
if (listOfProposals.Count > 0 || listOfQuotations.Count > 0)
{
string message = string.Empty;
message += listOfProposals.Count > 0 ? "Cannot delete deal, this deal is linked to:\nProposals\n" : "Cannot delete deal, this deal is linked to:\n";
foreach (var item in listOfProposals)
{
message += $"- {item.Application}\n";
}
message += listOfQuotations.Count > 0 ? "Quotations:\n" : "";
foreach (var item in listOfQuotations)
{
message += $"- {item.Description}\n";
}
ufex = new UserFriendlyException("Ooops! There is a problem.", $"{message}");
throw ufex;
}
else
{
foreach (var item in listOfDealComments)
{
dealCommentRepo.Delete(item);
dealCommentRepo.SaveChanges();
}
if (deal != null)
{
repo.Delete(deal);
repo.SaveChanges();
}
}
}
}
}
}
}
catch
{
if(ufex != null)
throw ufex;
else
throw new UserFriendlyException("Ooops! There is a problem.",$"Deal with Id[{input.Id}] could not be deleted.");
}
}
Abp.Boilerplate 0.9.6 Abp.EntityFramework 0.9.6
解决方案
我过去遇到过同样的问题,为了解决这个问题,我必须确保项目引用的实体框架版本与解决方案中所有项目的实体框架版本相同。
如果需要在 DataContext 类中确保启用
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
关键是与 ABP 上下文生成的名称相同。
推荐阅读
- powershell - HTML 到 CSV 文件的转换
- powershell - 触发远程powershell脚本独立运行
- javascript - CSS 网格。我当前的布局在 chrome 上按预期工作,但在 Firefox 上没有
- c# - uwp 如何读取指定目录下的文件
- jenkins - 执行 TestNG 测试时出错,使用 Gradle 的 WebDriver 的 Cucumver 场景
- bash - 使用 bash 的部署脚本
- spring - 使用spring mvc处理thymeleaf中的一对多关系
- sql - Postgres查询以获取所有孩子的ID
- c++ - 安装期间未执行 CPP DLL CustomAction 代码
- go - systemd 日志游标如何工作?