を数えます。一般的な方法は、現在、私はこのコードを使用していますエンティティフレームワークで
public bool Delete(int companyId, int opportunityId)
{
var opportunity = _opportunityRepository.FindOne(companyId: companyId, opportunityId: opportunityId).FirstOrDefault();
if (!opportunity.Contacts.Where(x => x.IsDeleted = false).IsNullOrEmpty())
{
throw new UserFriendlyException(ErrorMessages.UserFriendly.UnableToDeleteEntityHasRelatedData);
}
opportunity.IsDeleted = true;
_opportunityRepository.Edit(opportunity);
CurrentUnitOfWork.Commit();
return true;
}
この方法は、繰り返し実行され、何百もの場所を配置するのに時間がかかります。
エンティティタイプをチェックし、リフレクションや別の方法を使用してICollection<T>
を実装したすべてのプロパティをチェックし、クエリを実行してカウントを確認できる汎用ファンクションにするにはどうすればよいですか?
[ForeignKey("DepartmentId")]
public virtual ICollection<DepartmentLocation> DepartmentLocations { get; set; }
[ForeignKey("DepartmentId")]
public virtual ICollection<EmployeePosition> EmployeePositions { get; set; }
関係でカスケード削除を有効にしないのはなぜですか? – haim770
カスケードを使用したくない場合は無効にしてください...削除時のカスケードのデフォルトは、必要なリレーションまたはオプションのリレーションに依存します... – grek40