public void SelectGenerator_WithWhereAndTotalRecords_Valid() { var sql = generator.GenerateSelectWithTotalMatchingCount(out IList <QueryInfo> queryParameters, new List <Expression <Func <Product, bool> > > { product => product.ProductName == "Ice Candy" }); var expected = $"SELECT * FROM `Product` WHERE `ProductName` = @ProductName;{Environment.NewLine}SELECT COUNT(*) FROM `Product` WHERE `ProductName` = @ProductName;"; Assert.AreEqual(expected, sql); Assert.AreEqual("Ice Candy", queryParameters.First(x => x.PropertyName == "ProductName").PropertyValue); }
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> > >()); }