I've added a column 'IsDeleted' to each entity during my Entity Framework 4. model and implemented an Interface for this. How do i accomplish this the organizations with 'IsDeleted' set to 'true' are overlooked by all Objectsets and Navigationproperties during my model? Blocking the end result using LinQ doesn't work i believe, since the result cannot be changed back to an ObjectSet.
Can anybody assist me to please?
BTW: My template creates ObjectSets within the context-class such as this:
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 qualities for that organizations like that one:
<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
What's the reason for your IsDeleted flag? Objects marked for deletion get their status up-to-date through the ObjectStateManager. You are able to determine whether an item continues to be marked for deletion before
SaveChanges() continues to be known as by querying the ObjectStateManager.
If you wish to exclude erased organizations out of your queries, call
SaveChanges() marking them for deletion.. You may also use
AcceptChanges() to get rid of organizations in the collection without carrying out the deletion towards the database.