public TEntity OnMapperAction <TEntity, TSource, TKey>(TEntity entity, TSource source, TKey key, MapperActionType actionType) where TEntity : class where TSource : class where TKey : IEntityKey { MapperContextKey mapperKey = new MapperContextKey(typeof(TEntity), key); _entries.AddOrUpdate(mapperKey, key => { return(new MapperContextEntry { Entity = entity, ActionType = actionType }); }, (key, entry) => { entry.ActionType = actionType; return(entry); }); return(entity); }
protected virtual Expression OnMapperAction(TypeMap typeMap, MapperActionType actionType) { return(Call("OnMapperAction", typeMap.Context, typeMap.Target, typeMap.Source, typeMap.TargetKey, Constant(actionType))); }
public TEntity OnMapperAction <TEntity, TSource, TKey>(TEntity entity, TSource source, TKey key, MapperActionType actionType) where TEntity : class where TSource : class where TKey : IEntityKey { if (actionType == MapperActionType.Load) { return(QueryProvider.Load(Set <TEntity>(), source)); } else { IStateManager stateManager = this.GetService <IStateManager>(); IEntityType entityType = Model.FindEntityType(typeof(TEntity)); IKey keyType = entityType.FindPrimaryKey(); InternalEntityEntry internalEntry = stateManager.TryGetEntry(keyType, key.ToObject()); EntityEntry <TEntity> entry; if (internalEntry != null) { entry = new EntityEntry <TEntity>(internalEntry); } else { entry = Entry(entity); } switch (actionType) { case MapperActionType.Attach: entry.State = EntityState.Unchanged; break; case MapperActionType.Create: entry.State = EntityState.Added; break; case MapperActionType.Delete: entry.State = EntityState.Deleted; break; case MapperActionType.Update: // Do nothing, as change tracking should detect the changes. break; } return(entry.Entity); } }