Looks like my code is the right solution to this problem.
Instead of doing all these, I will simply Override SaveChanges and enumerate all changes and save those changes in database with following order..
Instead of looking at entity keys one should extract association ends from object state entry. I saw a hint in Daniel Simmons' blog blogs.msdn.com/b/dsimmons/archive/2008/0... Here are some extension methods that I came up with (UsableValues is also from Daniel's blog): public static AssociationEndMember GetAssociationEnds( this ObjectStateEntry entry) { var fieldMetadata = entry.UsableValues().DataRecordInfo. FieldMetadata; return fieldMetadata.
Select( m => m. FieldType as AssociationEndMember).ToArray(); } public static AssociationEndMember GetOtherAssociationEnd( this ObjectStateEntry entry, AssociationEndMember end) { end. ValidateBelongsTo(entry); AssociationEndMember ends = entry.
GetAssociationEnds(); if (ends0 == end) { return ends1; } return ends0; } public static EntityKey GetEndEntityKey( this ObjectStateEntry entry, AssociationEndMember end) { end. ValidateBelongsTo(entry); AssociationEndMember ends = entry. GetAssociationEnds(); if (ends0 == end) { return entry.UsableValues()0 as EntityKey; } return entry.UsableValues()1 as EntityKey; } public static NavigationProperty GetNavigationProperty( this ObjectStateEntry entry, AssociationEndMember end) { end.
ValidateBelongsTo(entry); var otherEnd = entry. GetOtherAssociationEnd(end); var relationshipType = entry.EntitySet. ElementType; var key = entry.
GetEndEntityKey(end); var entitySet = key. GetEntitySet( entry. ObjectStateManager.
MetadataWorkspace); var property = entitySet.ElementType. NavigationProperties. Where( p => p.
RelationshipType == relationshipType && p. FromEndMember == end && p. ToEndMember == otherEnd) .SingleOrDefault(); return property; } ValidateBelongsTo extension method (UsableValue is another extension method from Daniel's blog): static void ValidateBelongsTo( this AssociationEndMember end, ObjectStateEntry entry) { if (!entry.
IsRelationship) { throw new ArgumentException("is not a relationship entry", "entry"); } var fieldMetadata = entry.UsableValues().DataRecordInfo. FieldMetadata; if (fieldMetadata0. FieldType as AssociationEndMember!
= end && fieldMetadata1. FieldType as AssociationEndMember! = end) { throw new InvalidOperationException(string.
Format( "association end {0} does not participate in the " + "relationship {1}", end, entry)); } }.
Instead of looking at entity keys one should extract association ends from object state entry. I saw a hint in Daniel Simmons' blog blogs.msdn.com/b/dsimmons/archive/2008/0.... Here are some extension methods that I came up with (UsableValues is also from Daniel's blog): public static AssociationEndMember GetAssociationEnds( this ObjectStateEntry entry) { var fieldMetadata = entry.UsableValues().DataRecordInfo.
FieldMetadata; return fieldMetadata. Select( m => m. FieldType as AssociationEndMember).ToArray(); } public static AssociationEndMember GetOtherAssociationEnd( this ObjectStateEntry entry, AssociationEndMember end) { end.
ValidateBelongsTo(entry); AssociationEndMember ends = entry. GetAssociationEnds(); if (ends0 == end) { return ends1; } return ends0; } public static EntityKey GetEndEntityKey( this ObjectStateEntry entry, AssociationEndMember end) { end. ValidateBelongsTo(entry); AssociationEndMember ends = entry.
GetAssociationEnds(); if (ends0 == end) { return entry.UsableValues()0 as EntityKey; } return entry.UsableValues()1 as EntityKey; } public static NavigationProperty GetNavigationProperty( this ObjectStateEntry entry, AssociationEndMember end) { end. ValidateBelongsTo(entry); var otherEnd = entry. GetOtherAssociationEnd(end); var relationshipType = entry.EntitySet.
ElementType; var key = entry. GetEndEntityKey(end); var entitySet = key. GetEntitySet( entry.
ObjectStateManager. MetadataWorkspace); var property = entitySet.ElementType. NavigationProperties.
Where( p => p. RelationshipType == relationshipType && p. FromEndMember == end && p.
ToEndMember == otherEnd) .SingleOrDefault(); return property; } ValidateBelongsTo extension method (UsableValue is another extension method from Daniel's blog): static void ValidateBelongsTo( this AssociationEndMember end, ObjectStateEntry entry) { if (!entry. IsRelationship) { throw new ArgumentException("is not a relationship entry", "entry"); } var fieldMetadata = entry.UsableValues().DataRecordInfo. FieldMetadata; if (fieldMetadata0.
FieldType as AssociationEndMember! = end && fieldMetadata1. FieldType as AssociationEndMember!
= end) { throw new InvalidOperationException(string. Format( "association end {0} does not participate in the " + "relationship {1}", end, entry)); } }.
I can't seem to find the ValidateBelongsTo method. Could you please help. – SolarX Sep 20 at 9:13 1 I updated the post with ValidateBelongsTo.
Its a sanity check, doesn't do any work though. – see me no more Sep 20 at 19:21.
Added | EntityState. Where(e => e. Var key0 = entry.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.