Determine the relationship with the filter?

Is there a way to create an association in an entity infrastructure that always applies the "where" filter?

Here is an example: Suppose I have a database that uses soft deletes, so each table has a column β€œdeleted”.

So, if I have a Customer object associated with Address (1: 0..n), I would like the Navigation Addresses property to always be filtered by the remote flag, so if I exit Customer.Addresses, the collection will only return addresses where deleted == 0.

Does anyone know how to do this?

+3
source share
1 answer

No no.

For the same reason, you cannot have a conditional foreign key.

TPH :

  • , AddressDeleted AddressNotDeleted
  • (AddressDeleted maps to Address when Deleted = 0)
  • Customer AddressDeleted.

, ctx.Customer.Include("AddressDeleted").Single(), , .

ctx.Customer.Addresses.OfType<AddressDeleted>().

?

+3

Source: https://habr.com/ru/post/1784002/


All Articles