public void CanSelectDistinctAggregationUserAggregateHelper() { var aggregations = Query <UserEntity>() .Distinct() .Select(x => new { avg = Aggregate.Average(x.Id) }); Assert.That(aggregations.Count(), Is.EqualTo(1)); }
public void SetsSourceIdToAggregateAverage() { var aggregate = Aggregate.Average(new[] { new CurrentConditions(Unique.Pressure, Unique.Temperature, Unique.Humidity, Unique.SourceId) }); Assert.AreEqual("AggregateAverage", aggregate.SourceId); }
public void ComplexExample6TypeCast() { var average = Session.FlowQuery <UserEntity>() .Select(x => new { AverageIdValue = (decimal)Aggregate.Average(x.Id) }); Assert.That(average.Count(), Is.EqualTo(1)); Assert.That(average.First().AverageIdValue, Is.EqualTo(2.5M)); }
public void AggregationsExample4Example1WithInferredGroupBy() { FlowQuerySelection <AverageLogOnsPerRoleModel> averageLogOnsPerRole = Session.FlowQuery <UserEntity>() .Select(x => new AverageLogOnsPerRoleModel { AverageLogOns = Aggregate.Average(x.NumberOfLogOns), Role = x.Role }); Assert.That(averageLogOnsPerRole.Count(), Is.EqualTo(3)); }
public void AggregationsExample8Example1WithSeparateGroupByWithoutProjection() { FlowQuerySelection <AverageLogOnsPerRoleModel> averageLogOnsPerRole = Session.FlowQuery <UserEntity>() .GroupBy(x => x.Role) .Select(x => new AverageLogOnsPerRoleModel { AverageLogOns = Aggregate.Average(x.NumberOfLogOns) }); Assert.That(averageLogOnsPerRole.Count(), Is.EqualTo(3)); }
public void AveragesPressure() { var p1 = Unique.Pressure; var p2 = Unique.Pressure; var aggregate = Aggregate.Average(new[] { new CurrentConditions(p1, Unique.Temperature, Unique.Humidity, Unique.SourceId), new CurrentConditions(p2, Unique.Temperature, Unique.Humidity, Unique.SourceId) }); Assert.AreEqual(AverageTwoValues(p1, p2), aggregate.Pressure); }
public void AveragesHumidity() { var h1 = Unique.Humidity; var h2 = Unique.Humidity; var aggregate = Aggregate.Average(new[] { new CurrentConditions(Unique.Pressure, Unique.Temperature, h1, Unique.SourceId), new CurrentConditions(Unique.Pressure, Unique.Temperature, h2, Unique.SourceId) }); Assert.AreEqual(AverageTwoValues(h1, h2), aggregate.Humidity); }
public void AveragesTemperature() { var t1 = Unique.Temperature; var t2 = Unique.Temperature; var aggregate = Aggregate.Average(new[] { new CurrentConditions(Unique.Pressure, t1, Unique.Humidity, Unique.SourceId), new CurrentConditions(Unique.Pressure, t2, Unique.Humidity, Unique.SourceId) }); Assert.AreEqual(AverageTwoValues(t1.Value, t2.Value), aggregate.Temperature.Value); }
public void GroupByThrowsIfProjectionIsAggregate() { Assert .That ( () => { DummyQuery <UserEntity>() .GroupBy(x => Aggregate.Average(x.Id)); }, Throws.InvalidOperationException ); }
public EquipmentBonus GetEquipmentBonus(long playerid) { Aggregate damagesum = Aggregate.Sum <EquippedItemInformation>(EntityField.Create <EquippedItemInformation>(e => e.Damage)); Aggregate armorsum = Aggregate.Sum <EquippedItemInformation>(EntityField.Create <EquippedItemInformation>(e => e.Armor)); Aggregate usageoptimum = Aggregate.Average(EntityField.Create <EquippedItemInformation>(e => e.UsageOptimum)); DataTable table = context.Database.Load <EquippedItemInformation>(i => damagesum, i => armorsum).Where(i => i.PlayerID == playerid).Execute(); return(new EquipmentBonus { Damage = Converter.Convert <int>(table.Rows[0][0], true), Armor = Converter.Convert <int>(table.Rows[0][1], true), WeaponCritical = context.Database.Load <EquippedItemInformation>(i => usageoptimum).Where(i => i.PlayerID == playerid && i.Type == ItemType.Armor).ExecuteScalar <int>(), ArmorCritical = context.Database.Load <EquippedItemInformation>(i => usageoptimum).Where(i => i.PlayerID == playerid && i.Type == ItemType.Weapon).ExecuteScalar <int>() }); }
public void AggregationsExample6Example3WithInferredGroupBy() { IPartialSelection <UserEntity, AverageLogOnsPerRoleModel> selectionBuilder = Session.FlowQuery <UserEntity>() .PartialSelect(x => new AverageLogOnsPerRoleModel { AverageLogOns = Aggregate.Average(x.NumberOfLogOns) }); selectionBuilder .Add(x => new AverageLogOnsPerRoleModel { Role = x.Role }); FlowQuerySelection <AverageLogOnsPerRoleModel> averageLogOnsPerRole = selectionBuilder .Select(); Assert.That(averageLogOnsPerRole.Count(), Is.EqualTo(3)); }
public void TestCasting() { TestCastingModel[] stuff = Query <UserEntity>() .Where(x => x.Id == 1) .Select(x => new TestCastingModel { Test1 = x.Id, Test2 = (decimal)Aggregate.Average(x.Id), Test3 = Aggregate.Average(x.Id), Test4 = x.Id, Test5 = x.Id, Test6 = x.Id }) .ToArray(); Assert.That(stuff.Length, Is.EqualTo(1)); Assert.That(stuff[0].Test1, Is.EqualTo(1)); Assert.That(stuff[0].Test2, Is.EqualTo(1)); Assert.That(stuff[0].Test3, Is.EqualTo(1)); Assert.That(stuff[0].Test4, Is.EqualTo(1)); Assert.That(stuff[0].Test5, Is.EqualTo(1)); Assert.That(stuff[0].Test6, Is.EqualTo(1)); }
public void CanSelectAggregationUsingAggregateHelper() { var aggregation = Query <UserEntity>() .Select(u => new { Avg = Aggregate.Average(u.Id), Sum = Aggregate.Sum(u.Id), Min = Aggregate.Min(u.Id), Max = Aggregate.Max(u.Id), Cnt = Aggregate.Count(u.Id), Cnd = Aggregate.CountDistinct(u.Id) }); Assert.That(aggregation.Count(), Is.EqualTo(1)); var a = aggregation.First(); Assert.That(a.Avg, Is.EqualTo(2.5)); Assert.That(a.Sum, Is.EqualTo(10)); Assert.That(a.Min, Is.EqualTo(1)); Assert.That(a.Max, Is.EqualTo(4)); Assert.That(a.Cnt, Is.EqualTo(4)); Assert.That(a.Cnd, Is.EqualTo(4)); }
public void AggregationsExample5Example2WithInferredGroupBy() { FlowQuerySelection <AverageLogOnsPerRoleModel> averageLogOnsPerRole = Session.FlowQuery <UserEntity>() .Select <AverageLogOnsPerRoleModel>() .For(x => x.AverageLogOns).Use(x => Aggregate.Average(x.NumberOfLogOns)) .For(x => x.Role).Use(x => x.Role) .Select(); Assert.That(averageLogOnsPerRole.Count(), Is.EqualTo(3)); }
public void AverageThrowsWhenCalledOutsideLambdaExpression() { Assert.That(() => Aggregate.Average(3), Throws.InstanceOf <InvalidOperationException>()); Assert.That(() => Aggregate.Average((int?)3), Throws.InstanceOf <InvalidOperationException>()); }
public void CanSelectAggregationUsingAggregateHelper() { // avg IDetachedFlowQuery <UserEntity> aggregation = DetachedQuery <UserEntity>() .Select(u => Aggregate.Average(u.Id)); IEnumerable <UserEntity> users = Query <UserEntity>() .Where(x => x.Id, FqIs.GreaterThan(aggregation)) .Select(); Assert.That(users.Count(), Is.EqualTo(2)); // sum aggregation = DetachedQuery <UserEntity>() .Select(u => Aggregate.Sum(u.Id)); users = Query <UserEntity>() .Where(x => x.Id, FqIs.LessThan(aggregation)) .Select(); Assert.That(users.Count(), Is.EqualTo(4)); // min aggregation = DetachedQuery <UserEntity>() .Select(u => Aggregate.Min(u.Id)); users = Query <UserEntity>() .Where(x => x.Id, FqIs.EqualTo(aggregation)) .Select(); Assert.That(users.Count(), Is.EqualTo(1)); Assert.That(users.First().Id, Is.EqualTo(1)); // max aggregation = DetachedQuery <UserEntity>() .Select(u => Aggregate.Max(u.Id)); users = Query <UserEntity>() .Where(x => x.Id, FqIs.EqualTo(aggregation)) .Select(); Assert.That(users.Count(), Is.EqualTo(1)); Assert.That(users.First().Id, Is.EqualTo(4)); // count aggregation = DetachedQuery <UserEntity>() .Select(u => Aggregate.Count(u.Id)); users = Query <UserEntity>() .Where(x => x.Id, FqIs.EqualTo(aggregation)) .Select(); Assert.That(users.Count(), Is.EqualTo(1)); Assert.That(users.First().Id, Is.EqualTo(4)); // count distinct aggregation = DetachedQuery <UserEntity>() .Select(u => Aggregate.CountDistinct(u.Id)); users = Query <UserEntity>() .Where(x => x.Id, FqIs.EqualTo(aggregation)) .Select(); Assert.That(users.Count(), Is.EqualTo(1)); Assert.That(users.First().Id, Is.EqualTo(4)); // group by aggregation = DetachedQuery <UserEntity>() .Select(x => Aggregate.GroupBy(x.Id)); users = Query <UserEntity>() .Where(x => x.Id, FqIs.In(aggregation)) .Select(); Assert.That(users.Count(), Is.EqualTo(4)); }