Retrieving all data matching search criteria specified in a method name

object edited this page Oct 9, 2012 · 7 revisions

Simple.Data method FindAllBy is used to retrieve all data that satisfy search criteria.


Find all products with the given name

IEnumerable<dynamic> products = _db.Products.FindAllByProductName("Chai");
Assert.NotEmpty(products);

Request URI: GET Products?$filter=ProductName+eq+%27Chai%27


Find all products with the given name using different naming convention

IEnumerable<dynamic> products = _db.Products.FindAllByProduct_Name("Chai");
Assert.NotEmpty(products);

Request URI: GET Products?$filter=ProductName+eq+%27Chai%27


Find the count of all products with the given name

var count = _db.Products.FindAllByProductName("Chai").Count();
Assert.Equal(1, count);

Request URI: GET Products/$count?$filter=ProductName+eq+%27Chai%27


Find all products with the given name and return its count and the first row

Promise<int> count;
IEnumerable<dynamic> products = _db.Products.FindAllByProductName("Chai").WithTotalCount(out count).Take(1);
Assert.NotEmpty(products);
Assert.Equal(1, count);

Request URI: GET Products?$filter=ProductName+eq+%27Chai%27&$top=1&$inlinecount=allpages


See also:
Retrieving data
Simple.Data documentation for FindAll