user702769
user702769

Reputation: 2445

Something I don't quite understand about Conditional Mappings

In most cases, we can map a field in a table either to a property or we can map it using conditional mapping, but not both. Only exception is if condition is set to Is NotNull, since then we can also map to a column.

a) Is this the reason why we are able to map a DB column only once - namely, if field was allowed to have both a property mapping and a conditional mapping, then property mapping would tell EF to retrieve all table rows, while conditional mapping would tell EF to retrieve only those rows that satisfy the condition?!

b) If my reasoning under a) is correct, then why is field allowed to have both mappings when condition is set to Is NotNull? Why won't that create a conflict?

Thank you

Upvotes: 0

Views: 156

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364349

Mapping with condition Is NotNull has special meaning because it requires subsequent change in your model. The mapped property in the model must not be nullable. So your column in the database is nullable, your mapping condition filters all records with null value and your property always receives only records with non-null values. Also you can never assign null to the property.

In case of common condition with value equality this special behaviour is not possible.

Upvotes: 2

Related Questions