Open Closed

Linq Include on deleted rows #2892

ricavir created


While implementing my entities on my zero project (angular 2), I'm facing following issue. I have two entities AccountingCode and VatCode. VatCode has a reference to AccountingCode (I took your step-by-step document has an example)

When I try the following applicationservice method, it works great :

public async Task<PagedResultDto<VatCodeListDto>> GetVatCodes(GetVatCodesInput input)
            var vatCodes = _vatCodeRepository
                    p => p.Description.Contains(input.Filter) ||

            var resultCount = await vatCodes.CountAsync();
            var results = await vatCodes

            var eventTypeListDtos = results.MapTo<List<VatCodeListDto>>();

            return new PagedResultDto<VatCodeListDto>(resultCount, eventTypeListDtos);


AccountingCode entity is added to the result without lazy loading by adding the line : .Include(p=>p.AccountingCode)

The problem is when I delete an element from AcountingCode table that was linked to a VatCode element. In that case, the previous query removes all vatcode elements that where linked to the deleted AccountingCode element => but they are still in the database.

If I remove the line .Include(p=>p.AccountingCode), it works fine : all VatCode elements are sent to the client (with no AccountingCode linked to it).

Do you know how to proceed in order to keep Include method in the query (and avoid lazy loading) ?

1 Answer(s)
  • 0
    ismcagdas created
    Support Team


    I think .Include(p=>p.AccountingCode) uses an inner join. You can change your query to use a left join linq syntax, see <a class="postlink" href=""> ... touterjoin</a>.

    Please let us know if it does not work.