@@ -82,21 +82,17 @@ public override void AddEntity(Object dataContext, ODataResourceBase entry)
8282 {
8383 var context = ( DbContext ) dataContext ;
8484 EntityEntry < TEntity > entityEntry = context . Add ( CreateEntity ( context , entry ) ) ;
85- InternalEntityEntry internalEntry = entityEntry . GetInfrastructure ( ) ;
86- AddInstanceAnnotation ( entry , internalEntry ) ;
85+ AddInstanceAnnotation ( entry , entityEntry ) ;
8786
8887 IReadOnlyList < IProperty > keyProperties = _entityType . FindPrimaryKey ( ) . Properties ;
8988 for ( int i = 0 ; i < keyProperties . Count ; i ++ )
9089 if ( keyProperties [ i ] . ValueGenerated == ValueGenerated . OnAdd )
91- {
92- Object value = internalEntry . GetCurrentValue ( keyProperties [ i ] ) ;
93- internalEntry . SetTemporaryValue ( keyProperties [ i ] , value , false ) ;
94- }
90+ entityEntry . Property ( keyProperties [ i ] . Name ) . IsTemporary = true ;
9591 }
96- private static void AddInstanceAnnotation ( ODataResourceBase entry , InternalEntityEntry internalEntityEntry )
92+ private static void AddInstanceAnnotation ( ODataResourceBase entry , EntityEntry entityEntry )
9793 {
98- entry . InstanceAnnotations . Add ( new ODataInstanceAnnotation ( "ef.InternalEntityEntryValue" ,
99- new Infrastructure . OeOdataValue < InternalEntityEntry > ( internalEntityEntry ) ) ) ;
94+ var odataValue = new Infrastructure . OeOdataValue < EntityEntry > ( entityEntry ) ;
95+ entry . InstanceAnnotations . Add ( new ODataInstanceAnnotation ( "ef.EntityEntryValue" , odataValue ) ) ;
10096 }
10197 public override void AttachEntity ( Object dataContext , ODataResourceBase entry )
10298 {
@@ -105,15 +101,15 @@ public override void AttachEntity(Object dataContext, ODataResourceBase entry)
105101 if ( internalEntry == null )
106102 {
107103 TEntity entity = CreateEntity ( context , entry ) ;
108- internalEntry = context . Attach ( entity ) . GetInfrastructure ( ) ;
109- AddInstanceAnnotation ( entry , internalEntry ) ;
104+ EntityEntry entityEntry = context . Attach ( entity ) ;
105+ AddInstanceAnnotation ( entry , entityEntry ) ;
110106
111- IKey key = _entityType . FindPrimaryKey ( ) ;
107+ IReadOnlyList < IProperty > keyProperties = _entityType . FindPrimaryKey ( ) . Properties ;
112108 foreach ( ODataProperty odataProperty in entry . Properties )
113109 {
114110 IProperty property = _entityType . FindProperty ( odataProperty . Name ) ;
115- if ( ! key . Properties . Contains ( property ) )
116- internalEntry . SetPropertyModified ( property ) ;
111+ if ( ! keyProperties . Contains ( property ) )
112+ entityEntry . Property ( property . Name ) . IsModified = true ;
117113 }
118114 }
119115 else
@@ -168,11 +164,11 @@ private InternalEntityEntry GetEntityEntry(T context, ODataResourceBase entity)
168164 }
169165 private Object [ ] GetKeyValues ( ODataResourceBase entity )
170166 {
171- IKey key = _entityType . FindPrimaryKey ( ) ;
172- var keyValues = new Object [ key . Properties . Count ] ;
167+ IReadOnlyList < IProperty > keyProperties = _entityType . FindPrimaryKey ( ) . Properties ;
168+ var keyValues = new Object [ keyProperties . Count ] ;
173169 for ( int i = 0 ; i < keyValues . Length ; i ++ )
174170 {
175- String keyName = key . Properties [ i ] . Name ;
171+ String keyName = keyProperties [ i ] . Name ;
176172 foreach ( ODataProperty odataProperty in entity . Properties )
177173 if ( String . Compare ( odataProperty . Name , keyName , StringComparison . OrdinalIgnoreCase ) == 0 )
178174 {
@@ -232,12 +228,12 @@ public override void RemoveEntity(Object dataContext, ODataResourceBase entry)
232228 public override void UpdateEntityAfterSave ( Object dataContext , ODataResourceBase resource )
233229 {
234230 foreach ( ODataInstanceAnnotation instanceAnnotation in resource . InstanceAnnotations )
235- if ( instanceAnnotation . Value is Infrastructure . OeOdataValue < InternalEntityEntry > internalEntry )
231+ if ( instanceAnnotation . Value is Infrastructure . OeOdataValue < EntityEntry > entityEntry )
236232 {
237- PropertyValues propertyValues = internalEntry . Value . ToEntityEntry ( ) . CurrentValues ;
233+ PropertyValues propertyValues = entityEntry . Value . CurrentValues ;
238234 foreach ( ODataProperty odataProperty in resource . Properties )
239235 {
240- IProperty property = internalEntry . Value . EntityType . FindProperty ( odataProperty . Name ) ;
236+ IProperty property = entityEntry . Value . Property ( odataProperty . Name ) . Metadata ;
241237 if ( property . ValueGenerated != ValueGenerated . Never || property . IsForeignKey ( ) )
242238 odataProperty . Value = OeEdmClrHelper . CreateODataValue ( propertyValues [ property ] ) ;
243239 }
0 commit comments