T IQueryExecutor.ExecuteScalar <T>(QueryModel queryModel) { if (queryModel.ResultOperators.OfType <AnyResultOperator>().Any()) { var storage = _schema.StorageFor(queryModel.SelectClause.Selector.Type); var anyCommand = storage.AnyCommand(queryModel); return(_runner.Execute(conn => { anyCommand.Connection = conn; return (T)anyCommand.ExecuteScalar(); })); } if (queryModel.ResultOperators.OfType <CountResultOperator>().Any()) { var storage = _schema.StorageFor(queryModel.SelectClause.Selector.Type); var countCommand = storage.CountCommand(queryModel); return(_runner.Execute(conn => { countCommand.Connection = conn; var returnValue = countCommand.ExecuteScalar(); return Convert.ToInt32(returnValue).As <T>(); })); } throw new NotSupportedException(); }
public void DeleteEntity <T>(T entity) { var id = _schema.StorageFor(typeof(T)).Identity(entity); var list = _deletes.GetOrAdd(typeof(T), _ => new List <PendingDeletion>()); list.Add(new PendingDeletion(typeof(T), id, entity)); }
private string findJsonById <T>(object id) { var storage = _schema.StorageFor(typeof(T)); var loader = storage.LoaderCommand(id); return(_connection.Execute(loader, c => loader.ExecuteScalar() as string)); }
public void Delete <T>(T entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } _unitOfWork.DeleteEntity(entity); var storage = _schema.StorageFor(typeof(T)); storage.Remove(_identityMap, entity); }
public when_deriving_the_table_definition_from_the_database_schema_Tests() { _schema = theStore.Schema; theMapping = _schema.MappingFor(typeof(User)).As<DocumentMapping>(); theMapping.DuplicateField("UserName"); _storage = _schema.StorageFor(typeof(User)); theDerivedTable = _schema.DbObjects.TableSchema(theMapping); }
public when_deriving_the_table_definition_from_the_database_schema_Tests() { _schema = theStore.Schema; theMapping = _schema.MappingFor(typeof(User)).As <DocumentMapping>(); theMapping.DuplicateField("UserName"); _storage = _schema.StorageFor(typeof(User)); theDerivedTable = _schema.DbObjects.TableSchema(theMapping); }
public Guid StartStream <T>(params IEvent[] events) where T : IAggregate { // TODO --- temp! var streamStorage = _schema.StorageFor(typeof(Stream <T>)) as IAggregateStorage; var stream = Guid.NewGuid(); events.Each(@event => { var mapping = _schema.Events.EventMappingFor(@event.GetType()); appendEvent(mapping, stream, @event, streamStorage.StreamTypeName); }); return(stream); }
private Action <TInclude> GetJoinDictionaryCallback <TKey, TInclude>(PropertyInfo property, IncludeResultOperator @operator, ICompiledQuery <TDoc, TOut> query) { var queryProperty = GetPropertyInfo(property, @operator); var storage = _schema.StorageFor(typeof(TInclude)); var dictionary = (IDictionary <TKey, TInclude>)(queryProperty).GetValue(query); if (dictionary == null) { queryProperty.SetValue(query, new Dictionary <TKey, TInclude>()); dictionary = (IDictionary <TKey, TInclude>)queryProperty.GetValue(query); } return(x => { var id = storage.Identity(x).As <TKey>(); if (!dictionary.ContainsKey(id)) { dictionary.Add(id, x); } }); }
private Task <T> load <T>(object id) where T : class { if (_identityMap.Has <T>(id)) { return(Task.FromResult(_identityMap.Retrieve <T>(id))); } var source = new TaskCompletionSource <T>(); var mapping = _schema.MappingFor(typeof(T)); var parameter = _command.AddParameter(id); _command.AppendQuery( $"select {mapping.SelectFields("d")} from {mapping.TableName} as d where id = :{parameter.ParameterName}"); var handler = new SingleResultReader <T>(source, _schema.StorageFor(typeof(T)), _identityMap); addHandler(handler); return(source.Task); }
private IResolver <T> resolver <T>() { return(_schema.StorageFor(typeof(T)).As <IResolver <T> >()); }
/// <summary> /// Compiles all of the IDocumentStorage classes upfront for all known document types /// </summary> /// <returns></returns> public IList <IDocumentStorage> PrecompileAllStorage() { return(Options.AllDocumentMappings.Select(x => _schema.StorageFor(x.DocumentType)).ToList()); }
private IDocumentStorage storage <T>() { return(_schema.StorageFor(typeof(T))); }
public void DeleteEntity <T>(T entity) { var id = _schema.StorageFor(typeof(T)).Identity(entity); delete <T>(id); }