How to calculate Australian Golf Handicap using XPO

ASP.NET Team Blog
16 July 2010

Check out this informative code central example that shows you how to calculate the Australian Golf Handicap using eXpress Persistent Objects (XPO):

Example Details: How to calculate Australian Golf Handicap using XPO


The example demonstrates how to use the ASPxGridView with XPO to calculate the handicap used in Australian golf. The calculation algorithm and some sample data come from the The "Rolling Sample" Handicap Calculation Method article.

The sample features:

  • Linq-To-Xpo demonstration
  • Instead of unbound columns, non persistent fields of XPO objects are used
  • Editing similar to master-detail relationship

And it’s a complete sample. For example, here is the Player.cs file which defines the ‘Player’ class. To see the VB.NET version of this project, click the ‘Programming Language’ dropdown on the sample

using System;
using System.Linq;
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
using System.Collections.Generic;

public class Player : XPObject {
    const Double BonusForExcellense = 0.96;

    public Player()
        : base() { }

    public Player(Session session)
        : base(session) { }

    public override void AfterConstruction() {

    protected String _Name;
    public String Name {
        get { return _Name; }
        set { SetPropertyValue<String>("Name", ref _Name, value); }

    public Int32 Handicap {
        get {
            List<Result> results = LastBestTen();

            if (results.Count == 0)
                return 0;

            Double handicap = 0.0;

            handicap = results.Average<Result>(x => x.PlayedTo); // average
            handicap *= BonusForExcellense; // avarage * 0.96
            handicap = Math.Round(Math.Truncate(handicap * 10) / 10); // 14.496 -> 14.4 -> 14

            return Convert.ToInt32(handicap);

    [Association("Player-Results", typeof(Result))]
    public XPCollection<Result> Results {
        get { return GetCollection<Result>("Results"); }

    public List<Result> LastBestTen() {
        if (Results.Count <= 10)
            return Results.ToList<Result>();

        XPQuery<Result> results = new XPQuery<Result>(this.Session);

        var list1 = (from r in results
                     where (r.Player == this)
                     orderby r.Date descending
                     select r).Take(20).ToList<Result>();

        var list2 = (from r in list1
                     orderby r.PlayedTo ascending
                     select r).Take(10);

        return list2.ToList<Result>();

Click and Run

You can download and run the Code Central samples direct from your local machine. Just click the ‘Download Source Code’ button for the sample page.

Watch the ‘How To Use Code Central’ video to learn more:


Thanks Vest!

Vest, one of our awesome support engineers, created this sample for one of our awesome customers, Daryn.

Check out the ‘Australian Gold Handicap using XPO’ sample. Then drop me a line below with your thoughts.

Follow MehulHarry on Twitter

DXperience? What's That?

DXperience is the .NET developer's secret weapon. Get full access to a complete suite of professional components that let you instantly drop in new features, designer styles and fast performance for your applications. Try a fully-functional version of DXperience for free now:


Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.