private static IExtensibleEntity CreateObject(Type entityType, DbDataReader record, ExtensibleObjectContextBase context, bool updatableFromCache, bool skipDeletedItems, out IExtensibleEntity deletedEntity) { IExtensibleEntity returnEntity = null; deletedEntity = null; EntityKey key = CreateEntityKey(entityType, record); EntityCacheEntry entry = context.Cache.FindCacheEntry(key); if (entry != null) { returnEntity = entry.Entity; switch (entry.State) { case EntityRowState.Added: throw new InvalidOperationException("Added entity already exists in the cache"); case EntityRowState.Deleted: deletedEntity = entry.Entity; break; } if (deletedEntity != null && skipDeletedItems) { return(null); } else { return(returnEntity); //return the entity from the cache } } returnEntity = CreateEntity(entityType, record, context, true); //create entity from db record context.Cache.AddEntry(returnEntity, false); return(returnEntity); }
internal void Reset() { DetachCacheFromEntity(); _cache = null; _entity = null; _entryState = EntityRowState.Detached; }
internal EntityCacheEntry AddEntry(IExtensibleEntity entity, bool newInstance) { //if (entity.Key == null) // throw new ArgumentNullException("entity.Key"); //TODO: If auto generate key is setted, generate the key values first //TODO: create entity key with key values if (entity.Key == null) { //create entity key entity.Key = new EntityKey((entity as ExtensibleEntity).Metadata, (entity as ExtensibleEntity).KeyValues); } //see whether these's a key confliction EntityCacheEntry entry = this.FindCacheEntry(entity.Key); if (entry != null) { if (entry.Entity != entity) //key conflict { throw new ArgumentException("key already exists", "entity"); } if (entry.State == EntityRowState.Deleted) { //entry.RevertDelete(); } return(entry); } entry = new EntityCacheEntry(entity, this, newInstance); entry.AttachCacheToEntity(); this.AddCacheEntryToDictionary(entry, entry.State); return(entry); }
internal EntityCacheEntry Add(IExtensibleEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } return(this.AddEntry(entity, true)); }
public void AddObject(IExtensibleEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } AssertNotDisposed(); this.Cache.Add(entity); ExtensibleEntity entityObject = entity as ExtensibleEntity; if (entityObject != null) { //TODO: Add context to relationships } }
public void DeleteObject(IExtensibleEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } this.AssertNotDisposed(); if (entity.Key == null) { throw new ArgumentNullException("Can not delete entity without key", "entity"); } EntityCacheEntry entry = this.Cache.FindCacheEntry(entity.Key); if ((entry == null) || !object.ReferenceEquals(entry.Entity, entity)) { throw new InvalidOperationException("Can not delete entity not in cache"); } entry.Delete(); }
public EntityCacheEntry(IExtensibleEntity entity, ExtensibleObjectCache cache, bool newInstance) { _entryState = newInstance ? EntityRowState.Added : EntityRowState.Unchanged; _entity = entity; _cache = cache; }
internal static object CreateObject(Type entityType, DbDataReader record, ExtensibleObjectContextBase context, bool skipDeletedItems, out IExtensibleEntity deletedEntity) { return(CreateObject(entityType, record, context, false, skipDeletedItems, out deletedEntity)); }