CodeFluent相关集合排序
CodeFluent related collection sorting
我有两个 CodeFluentEntities 集合,它们在典型的 Master/Detail 关系中相关:发票和发票详细信息。
虽然我可以按发票编号顺序加载发票集合,但我不太明白如何让相关的发票详细信息集合按发票行编号顺序加载。
这适用于按所需顺序检索发票:
Dim _page As New CodeFluent.Runtime.PageOptions("[Invoice].[InvoiceNumber]", System.ComponentModel.ListSortDirection.Ascending)
Dim _orders as Accounting.AR.OrderCollection.PageLoadAll(0, -1, _page)
OrderCollectionBindingSource.DataSource = _orders
InvoiceDetail
集合以随机顺序加载。我想做的是将相关集合按 [InvoiceDetail].[LineNumber]
排序
CodeFluent Entities 提供了几个处理集合排序的选项:
- 静态排序:集合使用 CFQL 方法在 SQL 中排序。如果需要,您还可以覆盖 LoadBy...() 方法。但是,最好创建一个名为 LoadBy...OrderedBySomething() 的 CFQL 方法。
- 动态排序:集合根据排序参数在 SQL 中排序。
- 客户端排序:使用可以根据需要重写的 Sort 方法。
所有这些选项都记录在此处:http://www.softfluent.com/documentation/?BOM_SP_Sorting.html
在您的情况下,您想要更改 Orders
属性 用于加载相关订单集合的方法。所以你需要用静态排序创建一个新的 CFQL 方法(或替换现有的方法)。然后您可以使用 loadMethodName
属性将此方法设置为要使用的方法:
<cf:entity name="Customer">
<cf:property name="Id" key="true" />
<cf:property name="FullName" />
<!-- loadMethodName -->
<cf:property name="Orders" loadMethodName="LoadByCustomerOrderedByCreationDate" typeName="{0}.OrderCollection" relationPropertyName="Customer" />
</cf:entity>
<cf:entity name="Order">
<cf:property name="Id" key="true" />
<cf:property name="CreationDate" sortable="true" typeName="date" />
<cf:property name="Customer" typeName="{0}.Customer" relationPropertyName="Orders" />
<!-- Static sorting: `ORDER BY ...` -->
<cf:method name="LoadByCustomerOrderedByCreationDate" body="LOAD(Customer) WHERE Customer = @Customer ORDER BY CreationDate" />
</cf:entity>
Orders
属性 是:
public OrderCollection Orders
{
get
{
if (this._orders == null)
{
// code omitted for brevity
this._orders = OrderCollection.LoadByCustomerOrderedByCreationDate(this);
}
return this._orders;
}
}
我有两个 CodeFluentEntities 集合,它们在典型的 Master/Detail 关系中相关:发票和发票详细信息。
虽然我可以按发票编号顺序加载发票集合,但我不太明白如何让相关的发票详细信息集合按发票行编号顺序加载。
这适用于按所需顺序检索发票:
Dim _page As New CodeFluent.Runtime.PageOptions("[Invoice].[InvoiceNumber]", System.ComponentModel.ListSortDirection.Ascending)
Dim _orders as Accounting.AR.OrderCollection.PageLoadAll(0, -1, _page)
OrderCollectionBindingSource.DataSource = _orders
InvoiceDetail
集合以随机顺序加载。我想做的是将相关集合按 [InvoiceDetail].[LineNumber]
CodeFluent Entities 提供了几个处理集合排序的选项:
- 静态排序:集合使用 CFQL 方法在 SQL 中排序。如果需要,您还可以覆盖 LoadBy...() 方法。但是,最好创建一个名为 LoadBy...OrderedBySomething() 的 CFQL 方法。
- 动态排序:集合根据排序参数在 SQL 中排序。
- 客户端排序:使用可以根据需要重写的 Sort 方法。
所有这些选项都记录在此处:http://www.softfluent.com/documentation/?BOM_SP_Sorting.html
在您的情况下,您想要更改 Orders
属性 用于加载相关订单集合的方法。所以你需要用静态排序创建一个新的 CFQL 方法(或替换现有的方法)。然后您可以使用 loadMethodName
属性将此方法设置为要使用的方法:
<cf:entity name="Customer">
<cf:property name="Id" key="true" />
<cf:property name="FullName" />
<!-- loadMethodName -->
<cf:property name="Orders" loadMethodName="LoadByCustomerOrderedByCreationDate" typeName="{0}.OrderCollection" relationPropertyName="Customer" />
</cf:entity>
<cf:entity name="Order">
<cf:property name="Id" key="true" />
<cf:property name="CreationDate" sortable="true" typeName="date" />
<cf:property name="Customer" typeName="{0}.Customer" relationPropertyName="Orders" />
<!-- Static sorting: `ORDER BY ...` -->
<cf:method name="LoadByCustomerOrderedByCreationDate" body="LOAD(Customer) WHERE Customer = @Customer ORDER BY CreationDate" />
</cf:entity>
Orders
属性 是:
public OrderCollection Orders
{
get
{
if (this._orders == null)
{
// code omitted for brevity
this._orders = OrderCollection.LoadByCustomerOrderedByCreationDate(this);
}
return this._orders;
}
}