DevExpress eXpressApp Framework 和 eXpress Persistent Objects:排序列问题
DevExpress eXpressApp Framework and eXpress Persistent Objects : Sort column issue
我无法对 NonPersistent 列进行排序。 (DevExpress eXpressApp 框架(XAF)和 eXpress 持久对象(XPO))
这是我的代码
[Association("PCs-Gs", typeof(Allotments))]
public XPCollection<Allotments> PCs
{
get { return GetCollection<Allotments>("PCs"); }
}
[Association("SCs-Gs", typeof(Allotments))]
public XPCollection<Allotments> SCs
{
get { return GetCollection<Allotments>("SCs"); }
}
XPCollection<Allotments> _allAllotmentsCore;
public XPCollection<Allotments> AllAllotments
{
get
{
if (_allAllotmentsCore == null)
{
_allAllotmentsCore = new XPCollection<Allotments>(Session);
}
_allAllotmentsCore.Criteria = CriteriaOperator.Parse("PCGrower.Oid == ? OR SCGrower.Oid == ?", Oid);
_allAllotmentsCore.Sorting.Add(new SortProperty("Project.ProjectName", SortingDirection.Descending));
PopulateCollection(_allAllotmentsCore);
return _allAllotmentsCore;
}
}
private void PopulateCollection(XPCollection<Allotments> sourceCollection)
{
sourceCollection.AddRange(PCs);
sourceCollection.AddRange(SCs);
}
现在属性
[PersistentAlias("PCs[Project is not null].Count")] // THIS IS WORKING
//[PersistentAlias("AllAllotments[PCs.Project is not null].Count")] // THIS IS NOT WORKING
public int myCustomProperties
{
get { return Convert.ToInt32(EvaluateAlias("myCustomProperties")); }
}
如果在 NonPersistent 列上使用 PersistentAlias,那么我可以对该列进行排序。为此,我需要在 PersistentAlias 上添加逻辑。
以我为例:
我需要在 PersistentAlias 上添加此逻辑,例如 [PersistentAlias('whole logic')]
逻辑
public int myCustomProperties
{
get
{
int _myCustomProperties = 0;
Projects project = null;
foreach (Allotments obj in AllAllotments)
{
if (project != obj.Project && obj.Project != null)
{
project = obj.Project;
_myCustomProperties += 1;
}
}
return _myCustomProperties ;
}
}
让我们专注于逻辑
我使用了 AllAllotments(这不是协会属性)。
如果我像 [PersistentAlias('use AllAllotments')] 这样使用,那么我会出错。
但我使用像 [PersistentAlias("use PCs")] 然后工作。
唯一不同的是:PC(关联属性)和 AllAllotments(不是关联)。
所以,我的问题:
如何在 PersistentAlias 上使用 AllAllotments?
有人知道吗?
您可以使用免费加入。来自 DevExpress 文档。
With XPO, you can build criteria based on persistent objects that are
not directly related (don't have explicitly defined associations)
using Free Joins. In essence, XPO allows you to join any persistent
objects on a condition, calculate aggregate functions against matching
objects using their properties, and return aggregate values as the
result of joining. To accomplish this, use JoinOperands in your
criteria.
您可以在标准中使用它们,例如,
CriteriaOperator criteria =
CriteriaOperator.Parse("[<Orders>][^.EmployeeID = EmployeeID].Count() > 50");
XPCollection<Employee> employees = new XPCollection<Employee>(session, criteria);
或者您可以在 [PersistentAlias]
内使用它们。参见 this item from the DevExpress support center。
public class Department : BaseObject
{
private System.Int32? _TotalPhoneNumbers;
[PersistentAlias("[<PhoneNumber>][Party.<Contact>Department.Oid = ^.Oid and PhoneType='1'].Count()")]
public System.Int32? TotalPhoneNumbers {
get {
if (_TotalPhoneNumbers == null) {
_TotalPhoneNumbers = (int?)EvaluateAlias("TotalPhoneNumbers");
}
return _TotalPhoneNumbers;
}
}
}
有了 DevExpress 的所有东西,最好的地方就是他们的 support center。
我无法对 NonPersistent 列进行排序。 (DevExpress eXpressApp 框架(XAF)和 eXpress 持久对象(XPO)) 这是我的代码
[Association("PCs-Gs", typeof(Allotments))]
public XPCollection<Allotments> PCs
{
get { return GetCollection<Allotments>("PCs"); }
}
[Association("SCs-Gs", typeof(Allotments))]
public XPCollection<Allotments> SCs
{
get { return GetCollection<Allotments>("SCs"); }
}
XPCollection<Allotments> _allAllotmentsCore;
public XPCollection<Allotments> AllAllotments
{
get
{
if (_allAllotmentsCore == null)
{
_allAllotmentsCore = new XPCollection<Allotments>(Session);
}
_allAllotmentsCore.Criteria = CriteriaOperator.Parse("PCGrower.Oid == ? OR SCGrower.Oid == ?", Oid);
_allAllotmentsCore.Sorting.Add(new SortProperty("Project.ProjectName", SortingDirection.Descending));
PopulateCollection(_allAllotmentsCore);
return _allAllotmentsCore;
}
}
private void PopulateCollection(XPCollection<Allotments> sourceCollection)
{
sourceCollection.AddRange(PCs);
sourceCollection.AddRange(SCs);
}
现在属性
[PersistentAlias("PCs[Project is not null].Count")] // THIS IS WORKING
//[PersistentAlias("AllAllotments[PCs.Project is not null].Count")] // THIS IS NOT WORKING
public int myCustomProperties
{
get { return Convert.ToInt32(EvaluateAlias("myCustomProperties")); }
}
如果在 NonPersistent 列上使用 PersistentAlias,那么我可以对该列进行排序。为此,我需要在 PersistentAlias 上添加逻辑。
以我为例:
我需要在 PersistentAlias 上添加此逻辑,例如 [PersistentAlias('whole logic')]
逻辑
public int myCustomProperties
{
get
{
int _myCustomProperties = 0;
Projects project = null;
foreach (Allotments obj in AllAllotments)
{
if (project != obj.Project && obj.Project != null)
{
project = obj.Project;
_myCustomProperties += 1;
}
}
return _myCustomProperties ;
}
}
让我们专注于逻辑
我使用了 AllAllotments(这不是协会属性)。
如果我像 [PersistentAlias('use AllAllotments')] 这样使用,那么我会出错。
但我使用像 [PersistentAlias("use PCs")] 然后工作。
唯一不同的是:PC(关联属性)和 AllAllotments(不是关联)。
所以,我的问题:
如何在 PersistentAlias 上使用 AllAllotments?
有人知道吗?
您可以使用免费加入。来自 DevExpress 文档。
With XPO, you can build criteria based on persistent objects that are not directly related (don't have explicitly defined associations) using Free Joins. In essence, XPO allows you to join any persistent objects on a condition, calculate aggregate functions against matching objects using their properties, and return aggregate values as the result of joining. To accomplish this, use JoinOperands in your criteria.
您可以在标准中使用它们,例如,
CriteriaOperator criteria =
CriteriaOperator.Parse("[<Orders>][^.EmployeeID = EmployeeID].Count() > 50");
XPCollection<Employee> employees = new XPCollection<Employee>(session, criteria);
或者您可以在 [PersistentAlias]
内使用它们。参见 this item from the DevExpress support center。
public class Department : BaseObject
{
private System.Int32? _TotalPhoneNumbers;
[PersistentAlias("[<PhoneNumber>][Party.<Contact>Department.Oid = ^.Oid and PhoneType='1'].Count()")]
public System.Int32? TotalPhoneNumbers {
get {
if (_TotalPhoneNumbers == null) {
_TotalPhoneNumbers = (int?)EvaluateAlias("TotalPhoneNumbers");
}
return _TotalPhoneNumbers;
}
}
}
有了 DevExpress 的所有东西,最好的地方就是他们的 support center。