// Fetch all customers with no orders
var customers = new EntityCollection<CustomerEntity>();
var filter = new RelationPredicateBucket();
filter.Relations.Add(CustomerEntity.Relations.OrderEntityUsingCustomerId, JoinHint.Left);
filter.PredicateExpression.Add(OrderFields.OrderId == DBNull.Value);
using(var adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(customers, filter);
}
// Fetch all products that match product id's from the array
var ids = new[] { 1, 5, 8, 9 };
var products = new EntityCollection<ProductEntity>();
var rangePredicate = new FieldCompareRangePredicate(ProductFields.ProductId, null, ids);
var filter = new PredicateExpression(rangePredicate);
using(var adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(products, filter);
}
// Fetch all customers and only prefetch orders
// with TotalAmount bigger than 15
var customers = new EntityCollection<CustomerEntity>();
var prefetchPath = new PrefetchPath2(EntityType.CustomerEntity);
var orderPredicate = new PredicateExpression(OrderFields.TotalAmount > 15);
var orderPrefetchPath = prefetchPath.Add(CustomerEntity.PrefetchPathOrder, 0, orderPredicate);
using(var adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(customers, prefetchPath);
}
// Fetch all customers and only prefetch orders when
// the corresponding product price is bigger than 20
var customers = new EntityCollection<CustomerEntity>();
var prefetchPath = new PrefetchPath2(EntityType.CustomerEntity);
var orderBucket = new RelationPredicateBucket();
orderBucket.Relations.Add(OrderEntity.Relations.ProductEntityUsingProductId);
orderBucket.PredicateExpression.Add(ProductFields.Price > 20);
var orderPrefetchPath = prefetchPath.Add(CustomerEntity.PrefetchPathOrder, 0, orderBucket.PredicateExpression, orderBucket.Relations);
using(var adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(customers, prefetchPath);
}
// Fetch all products where the Name field cointains "blue" substring
var products = new EntityCollection<ProductEntity>();
var search = "blue";
var likePredicate = new FieldLikePredicate(ProductFields.Name, null, null, $"%{search}%");
var filter = new PredicateExpression(likePredicate);
using(var adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(products, filter);
}
// Fetch all products with price greater than 10
var products = new EntityCollection<ProductEntity>();
var filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(ProductFields.Price > 10);
// To filter by multiple fields at the same time, simply
// add additional predicate expressions to the filter
using(var adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(products, filter);
}
// Fetch all orders created by customers named "Joe"
var orders = new EntityCollection<OrderEntity>();
var filter = new RelationPredicateBucket();
filter.Relations.Add(OrderEntity.Relations.CustomerEntityUsingCustomerId);
filter.PredicateExpression.Add(CustomerFields.Name == "Joe");
using(var adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(orders, filter);
}
// Fetch OrderEntity with two associated nested entity types (CustomerEntity and ProductEntity)
var order = new OrderEntity(orderId);
var prefetchPath = new PrefetchPath2(EntityType.OrderEntity);
prefetchPath.Add(OrderEntity.PrefetchPathCustomer);
prefetchPath.Add(OrderEntity.PrefetchPathProduct);
using(var adapter = new DataAccessAdapter())
{
adapter.FetchEntity(order, prefetchPath);
}
// Fetch CustomerEntity with associated nested entities of Order type and subnested OrderStatusEntity
// and ProductEntity entities (which are in turn related to the OrderEntity)
var customer = new CustomerEntity(customerId);
var prefetchPath = new PrefetchPath2(EntityType.CustomerEntity);
var orderPrefetchPath = prefetchPath.Add(CustomerEntity.PrefetchPathOrder);
orderPrefetchPath.SubPath.Add(OrderEntity.PrefetchPathOrderStatus)
orderPrefetchPath.SubPath.Add(OrderEntity.PrefetchPathProduct)
using(var adapter = new DataAccessAdapter())
{
adapter.FetchEntity(customer, prefetchPath);
}