美好的一天
我正在努力删除软删除的记录,我有一个方法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();
});
}
});
}
这是PermanantlyDeleteComment
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
答案 0 :(得分:0)
我过去遇到过同样的问题,为了解决这个问题,我必须确保项目所引用的实体框架的版本与所有项目的实体框架的版本相同。解决方案。
如果在DataContext类中需要,请确保启用
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
关键是与ABP上下文生成的名称相同。