Ignore entries marked as deleted in navigation properties in EF 4.0

I added an “IsDeleted” column for each object in my Entity Framework 4.0 model and implemented an interface for it. How can I achieve that objects with "IsDeleted" set to "true" are ignored by all objects and navigation properties in my model? Filtering the result with LinQ does not work, I think, because the result cannot be converted back to an ObjectSet.

Can anybody help me?

BTW: My template generates ObjectSets in a context class as follows:

Private _Persons As ObjectSet(Of Person)
Public ReadOnly Property Persons() As ObjectSet(Of Person)
    Get
        If (_Persons Is Nothing) Then
            _Persons = MyBase.CreateObjectSet(Of Person)("Persons")
        End If
        Return _Persons
    End Get
End Property

and navigation properties for objects such as this:

<XmlIgnoreAttribute()>
<SoapIgnoreAttribute()>
<DataMemberAttribute()>
<EdmRelationshipNavigationPropertyAttribute("Model", "Map_Persons_Organisations", "Persons")>
 Public Property Persons() As EntityCollection(Of Person)
    Get
        Return CType(Me,IEntityWithRelationships).RelationshipManager.GetRelatedCollection(Of Person)("Model.Map_Persons_Organisations", "Persons")
    End Get
    Set
        If (Not value Is Nothing)
            CType(Me, IEntityWithRelationships).RelationshipManager.InitializeRelatedCollection(Of Person)("Model.Map_Persons_Organisations", "Persons", value)
        End If
    End Set
End Property
+3
source share
1

IsDeleted? , , ObjectStateManager. , , SaveChanges() ObjectStateManager.

, SaveChanges(), . AcceptChanges() .

-1

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


All Articles