Soft Deleted Data but issue while fetching | EF Core, C#

Viewed 105

I have an issue, I have 2 tables. as below.

public class Campaign
{
    public int CampaignId { get; set; }
    public string CampaignTitle { get; set; }
    public string CampaignObjective { get; set; }
    public int CurrencyId { get; set; }
    public Currency Currency { get; set; }
    public bool IsDeleted {get; set;}
}

public class Currency
{
    public int CurrencyId { get; set; }
    public string CurrencyTitle { get; set; }
    public bool IsDeleted {get; set;}
}

I am using GlobalQuery Filters to filter out Soft Deleted data.

entityConfiguration.HasQueryFilter(x => x.IsDeleted == false); 

I am using the below query

return await _context.Campaigns.Include(x => x.Currency).FirstOrDefaultAsync();

What is the best approach to the above query, to fetch related data ( which is deleted and required as well; in this case currency )

For End-user data is deleted, if i fetch and show, it will confuse user, if i do not fetch and pass Campaign.CurrencyId=null then model level error ( CurrencyId != null )

Any help will be appreciated, I have searched but could not find a solution or a better approach.

1 Answers

There must be some kind of solution with IgnoreQueryFilters like:

return await _context.Campaigns.IgnoreQueryFilters().Include(x => x.Currency).FirstOrDefaultAsync();
Related