Files to look at:
This example demonstrates how to find the object with the highest value from a collection. Here the Quote class has a collection of QuoteItem objects.
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#using System;
using System.Diagnostics;
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
using DevExpress.Xpo.DB;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
Quote q = Session.DefaultSession.FindObject<Quote>(new OperandProperty("Oid") == 1) as Quote;
if (q == null) {
q = new Quote();
for (int i = 0; i < 5; i++) {
QuoteItem qi = new QuoteItem();
qi.Sequence = i;
q.QuoteItems.Add(qi);
qi.Save();
}
q.Save();
}
int maxValue = Convert.ToInt32(
Session.DefaultSession.Evaluate<QuoteItem>(
CriteriaOperator.Parse("Max(Sequence)"),
new OperandProperty("Quote.Oid") == q.Oid
)
);
Debug.Assert(maxValue == 4, "Error");
XPCollection<QuoteItem> items = new XPCollection<QuoteItem>(
new OperandProperty("Quote.Oid") == q.Oid,
new SortProperty("Sequence", SortingDirection.Descending)
);
items.TopReturnedObjects = 1;
if (items.Count != 0) {
QuoteItem maxQuoteItemObject = items[0] as QuoteItem;
Debug.Assert(maxQuoteItemObject.Sequence == 4, "Error");
}
}
}
}
C#using DevExpress.Xpo;
namespace ConsoleApplication1 {
public class Quote : XPObject {
public Quote()
: base() {
// This constructor is used when an object is loaded from a persistent storage.
// Do not place any code here.
}
public Quote(Session session)
: base(session) {
// This constructor is used when an object is loaded from a persistent storage.
// Do not place any code here.
}
public override void AfterConstruction() {
base.AfterConstruction();
// Place here your initialization code.
}
private string _name;
public string Name {
get { return _name; }
set { SetPropertyValue("Name", ref _name, value); }
}
[Association("Quote-QuoteItems"), Aggregated]
public XPCollection<QuoteItem> QuoteItems {
get {
return GetCollection<QuoteItem>("QuoteItems");
}
}
}
}
C#using DevExpress.Xpo;
namespace ConsoleApplication1 {
public class QuoteItem : XPObject {
public QuoteItem()
: base() {
// This constructor is used when an object is loaded from a persistent storage.
// Do not place any code here.
}
public QuoteItem(Session session)
: base(session) {
// This constructor is used when an object is loaded from a persistent storage.
// Do not place any code here.
}
public override void AfterConstruction() {
base.AfterConstruction();
// Place here your initialization code.
}
private int _sequence;
public int Sequence {
get { return _sequence; }
set { SetPropertyValue("Sequence", ref _sequence, value); }
}
private Quote _quote;
[Association("Quote-QuoteItems")]
public Quote Quote {
get { return _quote; }
set { SetPropertyValue("Quote", ref _quote, value); }
}
}
}