You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classMyFirstTable{publicuintUserId{get;set;}publicstringMessage{get;set;}publicDateTimeTimestamp{get;set;}publicfloatMetric{get;set;}}classQuickStartDbContext:DbContext{protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder){base.OnConfiguring(optionsBuilder);optionsBuilder.UseClickHouse("Host=localhost;Protocol=http;Port=8123;Database=QuickStart");}publicDbSet<MyFirstTable>MyFirstTable{get;set;}protectedoverridevoidOnModelCreating(ModelBuildermodelBuilder){varentityTypeBuilder=modelBuilder.Entity<MyFirstTable>();entityTypeBuilder.Property(e =>e.UserId).HasColumnName("user_id");entityTypeBuilder.Property(e =>e.Message).HasColumnName("message");entityTypeBuilder.Property(e =>e.Timestamp).HasColumnName("timestamp");entityTypeBuilder.Property(e =>e.Metric).HasColumnName("metric");entityTypeBuilder.HasKey(e =>new{e.UserId,e.Timestamp});entityTypeBuilder.ToTable("my_first_table", table =>table.HasMergeTreeEngine().WithPrimaryKey("user_id","timestamp"));}}classProgram{staticasyncTaskMain(string[]args){awaitusingvarcontext=newQuickStartDbContext();awaitcontext.Database.EnsureCreatedAsync();awaitcontext.MyFirstTable.AddRangeAsync(newMyFirstTable{UserId=101,Message="Hello, ClickHouse!",Timestamp=DateTime.Now,Metric=-1f},newMyFirstTable{UserId=102,Message="Insert a lot of rows per batch",Timestamp=DateTime.Now.AddDays(-1),Metric=1.41421f},newMyFirstTable{UserId=102,Message="Sort your data based on your commonly-used queries",Timestamp=DateTime.Today,Metric=2.718f},newMyFirstTable{UserId=101,Message="Granules are the smallest chunks of data read",Timestamp=DateTime.Now.AddSeconds(5),Metric=3.14159f});awaitcontext.SaveChangesAsync();vardata=context.MyFirstTable.OrderBy(e =>e.Timestamp).ToArray();vartable=newTable().AddColumns(newTableColumn("user_id").RightAligned(),newTableColumn("message").LeftAligned(),newTableColumn("timestamp").RightAligned(),newTableColumn("metric").RightAligned());Array.ForEach(data, d =>table.AddRow(d.UserId.ToString(),d.Message,d.Timestamp.ToString(CultureInfo.InvariantCulture),d.Metric.ToString(CultureInfo.InvariantCulture)));AnsiConsole.Write(table);}}
┌─────────┬────────────────────────────────────────────────────┬─────────────────────┬─────────┐
│ user_id │ message │ timestamp │ metric │
├─────────┼────────────────────────────────────────────────────┼─────────────────────┼─────────┤
│ 102 │ Insert a lot of rows per batch │ 04/29/2024 21:05:26 │ 1.41421 │
│ 102 │ Sort your data based on your commonly-used queries │ 04/30/2024 00:00:00 │ 2.718 │
│ 101 │ Hello, ClickHouse! │ 04/30/2024 21:05:26 │ -1 │
│ 101 │ Granules are the smallest chunks of data read │ 04/30/2024 21:05:31 │ 3.14159 │
└─────────┴────────────────────────────────────────────────────┴─────────────────────┴─────────┘