Closed dangergrrl closed 1 year ago
I think it works.
[Fact]
public void TestLinqMax()
{
#if NET5_0_OR_GREATER
var random = Random.Shared;
#else
var random = new Random();
#endif
using var ms = new MemoryStream();
using var litedb = new LiteDatabase(ms);
var list = new List<TestModel>();
for (var a = 0; a < 100; ++a)
{
list.Add(new TestModel() { Count = random.Next() });
}
var max = list.Max(a => a.Count);
var collection = litedb.GetCollection<TestModel>();
collection.InsertBulk(list);
var maxFromCollection = collection.Max(a => a.Count);
Assert.Equal(max, maxFromCollection);
}
private class TestModel
{
public int Count { get; set; }
}
}
Sorry, I didn't want to actually try because my project is rather large and not debugged just now (lots of new code). Ty, mbdavid for all the wonderful code.
SELECT MAX(_id) FROM your_col
orcol.Query().Max(x => x.Id)
Originally posted by @mbdavid in https://github.com/mbdavid/LiteDB/issues/1128#issuecomment-442554881