private void RemoveFromCacheByForeignKey(T obj, EntityFrameworkContext context, IForeignKey foreignKey) { var foreignKeyProperty = foreignKey.Properties.First(); var foreignKeyValue = this.GetPropertyValue(obj, context, foreignKeyProperty); if (foreignKeyValue.HasValue) { if (this.byForeignKeyCache.TryGetValue(this.GetForeignKeyCacheKey(foreignKeyProperty.Name, foreignKeyValue.Value), out ISet <T> objList)) { objList.Remove(obj); } } }
private void AddToCacheByForeignKey(T obj, EntityFrameworkContext context, IForeignKey foreignKey) { var foreignKeyProperty = foreignKey.Properties.First(); var foreignKeyValue = this.GetPropertyValue(obj, context, foreignKeyProperty); if (foreignKeyValue.HasValue) { var cacheKey = this.GetForeignKeyCacheKey(foreignKeyProperty.Name, foreignKeyValue.Value); if (!this.byForeignKeyCache.TryGetValue(cacheKey, out ISet <T> objList)) { objList = new HashSet <T>(); this.byForeignKeyCache.Add(cacheKey, objList); } if (!objList.Contains(obj)) { objList.Add(obj); } } }
private Account LoadAccountByLoginNameByJsonQuery(string loginName, string password, EntityFrameworkContext context) { var manager = this.RepositoryManager as RepositoryManager; if (manager != null) { var accountInfo = context.Context.Set <Account>() .Select(a => new { a.Id, a.LoginName, a.PasswordHash }) .FirstOrDefault(a => a.LoginName == loginName && BCrypt.Verify(password, a.PasswordHash, false)); if (accountInfo != null) { manager.EnsureCachesForCurrentGameConfiguration(); context.Context.Database.OpenConnection(); try { var objectLoader = new AccountJsonObjectLoader(); return(objectLoader.LoadObject <Account>(accountInfo.Id, context.Context)); } finally { context.Context.Database.CloseConnection(); } } } return(null); }
private Guid?GetPropertyValue(T obj, EntityFrameworkContext context, IProperty property) { var entry = context.Context.Entry(obj); return((Guid?)entry.Property(property.Name).CurrentValue); }