csharp LLBLGen教程

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp LLBLGen教程相关的知识,希望对你有一定的参考价值。

// 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);
}

以上是关于csharp LLBLGen教程的主要内容,如果未能解决你的问题,请参考以下文章

llblgen 和 nHibernate 有啥区别?

ORM:LLBLGen 项目和其他

内部连接使用LLBLGen?

LLBLGen Pro v2.6 设计器问题

使用EntityCollectionBase.GetMulti()进行LLBLGen Pro 5.0缓存

使用 LLBLGen 时如何在 Linq 查询中进行全文搜索