public void Fill(Dictionary <LookupToken, IEnumerable> lookups, IRetriever retriever) { using (HeavyProfiler.Log("SQL", () => Command.PlainSql())) using (DbDataReader reader = Executor.UnsafeExecuteDataReader(Command)) { ProjectionRowEnumerator <KeyValuePair <K, V> > enumerator = new ProjectionRowEnumerator <KeyValuePair <K, V> >(reader, ProjectorExpression, lookups, retriever, CancellationToken.None); IEnumerable <KeyValuePair <K, V> > enumerabe = new ProjectionRowEnumerable <KeyValuePair <K, V> >(enumerator); try { var lookUp = enumerabe.ToLookup(a => a.Key, a => a.Value); lookups.Add(Token, lookUp); } catch (Exception ex) { FieldReaderException fieldEx = enumerator.Reader.CreateFieldReaderException(ex); fieldEx.Command = Command; fieldEx.Row = enumerator.Row; fieldEx.Projector = ProjectorExpression; throw fieldEx; } } }
protected void OnChange(object sender, SqlNotificationEventArgs args) { try { if (args.Info == SqlNotificationInfo.Invalid && args.Source == SqlNotificationSource.Statement && args.Type == SqlNotificationType.Subscribe) { throw new InvalidOperationException("Invalid query for SqlDependency") { Data = { { "query", query.PlainSql() } } } } ; if (args.Info == SqlNotificationInfo.PreviousFire) { throw new InvalidOperationException("The same transaction that loaded the data is invalidating it! Table: {0} SubTables: {1} ". FormatWith(Table, subTables?.Select(e => e.Table).ToString(","))) { Data = { { "query", query.PlainSql() } } } } ; if (CacheLogic.LogWriter != null) { CacheLogic.LogWriter.WriteLine("Change {0}".FormatWith(GetType().TypeName())); } Reset(); Interlocked.Increment(ref invalidations); controller.OnChange(this, args); } catch (Exception e) { e.LogException(); } }
private SqlPreCommandSimple PostgresDoBlock(string variableName, SqlPreCommandSimple declaration, SqlPreCommand block) { return(new SqlPreCommandSimple(@$ "DO $$ DECLARE {declaration.PlainSql().Indent(4)} BEGIN IF {variableName} IS NULL THEN RAISE EXCEPTION 'Not found'; END IF; {block.PlainSql().Indent(4)} END $$;")); }
public void Fill(Dictionary <LookupToken, IEnumerable> lookups, IRetriever retriever) { Dictionary <K, MList <V> > requests = (Dictionary <K, MList <V> >)lookups.TryGetC(Token); if (requests == null) { return; } using (HeavyProfiler.Log("SQL", () => Command.PlainSql())) using (DbDataReader reader = Executor.UnsafeExecuteDataReader(Command)) { ProjectionRowEnumerator <KeyValuePair <K, MList <V> .RowIdElement> > enumerator = new ProjectionRowEnumerator <KeyValuePair <K, MList <V> .RowIdElement> >(reader, ProjectorExpression, lookups, retriever, CancellationToken.None); IEnumerable <KeyValuePair <K, MList <V> .RowIdElement> > enumerabe = new ProjectionRowEnumerable <KeyValuePair <K, MList <V> .RowIdElement> >(enumerator); try { var lookUp = enumerabe.ToLookup(a => a.Key, a => a.Value); foreach (var kvp in requests) { var results = lookUp[kvp.Key]; ((IMListPrivate <V>)kvp.Value).InnerList.AddRange(results); ((IMListPrivate <V>)kvp.Value).InnerListModified(results.Select(a => a.Element).ToList(), null); retriever.ModifiablePostRetrieving(kvp.Value); } } catch (Exception ex) { FieldReaderException fieldEx = enumerator.Reader.CreateFieldReaderException(ex); fieldEx.Command = Command; fieldEx.Row = enumerator.Row; fieldEx.Projector = ProjectorExpression; throw fieldEx; } } }