public virtual void Do(string query, object parameters) { query = _queryGenerator.Query(query, parameters, out IList <QueryInfo> queryParameters); var cmd = new DotEntityDbCommand(DbOperationType.Select, query, queryParameters); DotEntityDbConnector.ExecuteCommand(cmd); }
public virtual TType DoScaler <TType>(string query, object parameters, Func <TType, bool> resultAction = null) { query = _queryGenerator.Query(query, parameters, out IList <QueryInfo> queryParameters); var cmd = new DotEntityDbCommand(DbOperationType.SelectScaler, query, queryParameters, commandBehavior: CommandBehavior.SingleRow); DotEntityDbConnector.ExecuteCommand(cmd); return(cmd.GetResultAs <TType>()); }
public virtual int DoUpdate <T>(T entity, Func <T, bool> resultAction = null) where T : class { var query = _queryGenerator.GenerateUpdate(entity, out IList <QueryInfo> queryParameters); var cmd = new DotEntityDbCommand(DbOperationType.Update, query, queryParameters); DotEntityDbConnector.ExecuteCommand(cmd); return(cmd.GetResultAs <int>()); }
public virtual int DoCount <T>(List <Expression <Func <T, bool> > > where, Func <int, bool> resultAction = null) where T : class { var query = _queryGenerator.GenerateCount(where, out IList <QueryInfo> queryParameters); var cmd = new DotEntityDbCommand(DbOperationType.SelectScaler, query, queryParameters, commandBehavior: CommandBehavior.SingleRow); DotEntityDbConnector.ExecuteCommand(cmd); return(cmd.GetResultAs <int>()); }
public virtual T DoSelectSingle <T>(List <Expression <Func <T, bool> > > where = null, Dictionary <Expression <Func <T, object> >, RowOrder> orderBy = null) where T : class { var query = _queryGenerator.GenerateSelect(out IList <QueryInfo> queryParameters, where, orderBy); var cmd = new DotEntityDbCommand(DbOperationType.Select, query, queryParameters, commandBehavior: CommandBehavior.SingleRow); cmd.ProcessReader(reader => DataDeserializer <T> .Instance.DeserializeSingle(reader, cmd)); DotEntityDbConnector.ExecuteCommand(cmd); return(cmd.GetResultAs <T>()); }
public virtual int DoDelete <T>(Expression <Func <T, bool> > where, Func <T, bool> resultAction = null) where T : class { TryGetFromCache(out string query, out IList <QueryInfo> queryParameters); query = query ?? _queryGenerator.GenerateDelete <T>(where, out queryParameters); TrySetCache(query, queryParameters); var cmd = new DotEntityDbCommand(DbOperationType.Delete, query, queryParameters); DotEntityDbConnector.ExecuteCommand(cmd); return(cmd.GetResultAs <int>()); }
public virtual T DoSingle <T>(string query, object parameters, Func <T, bool> resultAction = null) where T : class { var actualQuery = query; TryGetFromCache(out query, out IList <QueryInfo> queryParameters); query = query ?? _queryGenerator.Query(actualQuery, parameters, out queryParameters); TrySetCache(query, queryParameters); var cmd = new DotEntityDbCommand(DbOperationType.Select, query, queryParameters, commandBehavior: CommandBehavior.SingleRow); cmd.ProcessReader(reader => DataDeserializer <T> .Instance.DeserializeSingle(reader, cmd)); DotEntityDbConnector.ExecuteCommand(cmd); return(cmd.GetResultAs <T>()); }
public virtual int DoInsert <T>(T entity, Func <T, bool> resultAction = null) where T : class { var keyColumn = DataDeserializer <T> .Instance.GetKeyColumn(); var query = _queryGenerator.GenerateInsert(entity, out IList <QueryInfo> queryParameters); var cmd = new DotEntityDbCommand(DbOperationType.Insert, query, queryParameters, keyColumn); cmd.ProcessResult(result => { var id = result as int? ?? Convert.ToInt32(result); DataDeserializer <T> .Instance.SetPropertyAs <int>(entity, keyColumn, id); }); DotEntityDbConnector.ExecuteCommand(cmd); return(1); }
public virtual IEnumerable <T> DoSelect <T>(List <Expression <Func <T, bool> > > where = null, Dictionary <Expression <Func <T, object> >, RowOrder> orderBy = null, int page = 1, int count = int.MaxValue) where T : class { ThrowIfInvalidPage(orderBy, page, count); TryGetFromCache(out string query, out IList <QueryInfo> queryParameters); query = query ?? _queryGenerator.GenerateSelect(out queryParameters, where, orderBy, page, count); TrySetCache(query, queryParameters); var cmd = new DotEntityDbCommand(DbOperationType.Select, query, queryParameters); cmd.ProcessReader(reader => { return(DataDeserializer <T> .Instance.DeserializeMany(reader, cmd)); }); DotEntityDbConnector.ExecuteCommand(cmd); return(cmd.GetResultAs <IEnumerable <T> >()); }
public virtual Tuple <int, IEnumerable <T> > DoSelectWithTotalMatches <T>(List <Expression <Func <T, bool> > > where = null, Dictionary <Expression <Func <T, object> >, RowOrder> orderBy = null, int page = 1, int count = int.MaxValue) where T : class { ThrowIfInvalidPage(orderBy, page, count); TryGetFromCache(out string query, out IList <QueryInfo> queryParameters); query = query ?? _queryGenerator.GenerateSelectWithTotalMatchingCount(out queryParameters, where, orderBy, page, count); TrySetCache(query, queryParameters); var cmd = new DotEntityDbCommand(DbOperationType.Select, query, queryParameters); cmd.ProcessReader(reader => { var ts = DataDeserializer <T> .Instance.DeserializeMany(reader, cmd); reader.NextResult(); reader.Read(); var fv = reader[0]; var total = fv as int? ?? Convert.ToInt32(fv); return(Tuple.Create(total, ts)); }); DotEntityDbConnector.ExecuteCommand(cmd); return(cmd.GetResultAs <Tuple <int, IEnumerable <T> > >()); }