Max of Nullable using ValuesQuery.

Dec 30, 2013 at 4:34 AM
Am I doing something wrong?
I can't get the Max using ValuesQuery.
An CorruptedDatabaseException occours when I do it with the property Field2 (which is nullable).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NDatabase;
using NDatabase.Api;

namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args) {
            try {
                // Delete database if exists
                if (System.IO.File.Exists("database.ndb")) {
                    System.IO.File.Delete("database.ndb");
                }

                // Create a new database file
                using (var db = OdbFactory.Open("database.ndb")) {
                    // Include a new instance in the database
                    var newInst = new Example();
                    newInst.Field1 = 10;
                    newInst.Field2 = 10;
                    db.Store<Example>(newInst);
                    db.Commit();

                    // Max over Field1
                    var newID = Max(db, "Field1");
                    Console.WriteLine("Max of Field1 is {0}", newID);
                    // Max over Field2
                    newID = Max(db, "Field2");    // EXCEPTION OCCOURS HERE
                    Console.WriteLine("Max of Field2 is {0}", newID);
                }
            }
            catch (Exception ex) {
                // Error message                
                Console.WriteLine("Error: {0}", ex.ToString());
            }
            finally {
                // Wait until press any key
                Console.WriteLine();
                Console.WriteLine("Press any key to finish");
                Console.ReadKey();
            }
        }
        static int Max(IOdb db, string field) {
            var query = db.ValuesQuery<Example>();
            query.Max(field, "max");
            var values = query.Execute();
            var objectValues = values.NextValues();
            return int.Parse(objectValues.GetByAlias("max").ToString());
        }
    }

    class Example {
        public int Field1 { get; set; }
        public int? Field2 { get; set; }
    }
}
Dec 30, 2013 at 4:55 AM
Sorry,

This post is not in the correct place.
It's a issue, not a discussion item.

New post: https://ndatabase.codeplex.com/workitem/939