@@ -788,6 +788,69 @@ public void AddAggregateFunction_Should_Support_All_Aggregate_Types()
788788
789789 #endregion
790790
791+ #region AddAggregateFunction_Should_Support_Mismatched_Property_And_SourceColumn_Types
792+
793+ private class CountMismatch_TradeEntity
794+ {
795+ public DateTime Timestamp { get ; set ; }
796+ public string Ticker { get ; set ; } = string . Empty ;
797+ public decimal Price { get ; set ; }
798+ }
799+
800+ private class CountMismatch_TradeAggregate
801+ {
802+ public DateTime TimeBucket { get ; set ; }
803+ public int TradeCount { get ; set ; }
804+ public long TickerCount { get ; set ; }
805+ }
806+
807+ private class CountMismatch_Context : DbContext
808+ {
809+ public DbSet < CountMismatch_TradeEntity > Trades => Set < CountMismatch_TradeEntity > ( ) ;
810+ public DbSet < CountMismatch_TradeAggregate > HourlyTrades => Set < CountMismatch_TradeAggregate > ( ) ;
811+
812+ protected override void OnConfiguring ( DbContextOptionsBuilder optionsBuilder )
813+ => optionsBuilder . UseNpgsql ( "Host=localhost;Database=test;Username=test;Password=test" )
814+ . UseTimescaleDb ( ) ;
815+
816+ protected override void OnModelCreating ( ModelBuilder modelBuilder )
817+ {
818+ modelBuilder . Entity < CountMismatch_TradeEntity > ( entity =>
819+ {
820+ entity . HasNoKey ( ) ;
821+ entity . ToTable ( "Trades" ) ;
822+ entity . IsHypertable ( x => x . Timestamp ) ;
823+ } ) ;
824+
825+ modelBuilder . Entity < CountMismatch_TradeAggregate > ( entity =>
826+ {
827+ entity . HasNoKey ( ) ;
828+ entity . IsContinuousAggregate < CountMismatch_TradeAggregate , CountMismatch_TradeEntity > (
829+ "hourly_trades" ,
830+ "1 hour" ,
831+ x => x . Timestamp )
832+ . AddAggregateFunction ( x => x . TradeCount , x => x . Timestamp , EAggregateFunction . Count )
833+ . AddAggregateFunction ( x => x . TickerCount , x => x . Ticker , EAggregateFunction . Count ) ;
834+ } ) ;
835+ }
836+ }
837+
838+ [ Fact ]
839+ public void AddAggregateFunction_Should_Support_Mismatched_Property_And_SourceColumn_Types ( )
840+ {
841+ using CountMismatch_Context context = new ( ) ;
842+ IModel model = GetModel ( context ) ;
843+ IEntityType entityType = model . FindEntityType ( typeof ( CountMismatch_TradeAggregate ) ) ! ;
844+
845+ List < string > ? aggregateFunctions = entityType . FindAnnotation ( ContinuousAggregateAnnotations . AggregateFunctions ) ? . Value as List < string > ;
846+ Assert . NotNull ( aggregateFunctions ) ;
847+ Assert . Equal ( 2 , aggregateFunctions . Count ) ;
848+ Assert . Contains ( "TradeCount:Count:Timestamp" , aggregateFunctions ) ;
849+ Assert . Contains ( "TickerCount:Count:Ticker" , aggregateFunctions ) ;
850+ }
851+
852+ #endregion
853+
791854 #region AddGroupByColumn_Should_Add_Single_Column_From_Expression
792855
793856 private class AddGroupByColumn_Should_Add_Single_Column_From_Expression_MetricEntity
0 commit comments