ygl 3 years ago
parent fde07519c3
commit 675e512f72
  1. 2
      realm_cli/AppDbContext.cs
  2. 28
      realm_cli/Program.cs

@ -12,7 +12,7 @@ public class AppDbContext: DbContext
public AppDbContext()
{
SQLitePCL.Batteries_V2.Init();
this.Database.EnsureCreated();
//this.Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

@ -4,6 +4,9 @@ using System.Collections.Concurrent;
using System.ComponentModel;
using System.Diagnostics;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Serializers;
using realm_cli;
@ -202,7 +205,7 @@ async Task<LiveData> QueryLiveData()
Console.WriteLine($"{(DateTime.Now - b).TotalSeconds} secs");
return null;
}
/*
using (var db = GetDB())
{
db.Write(() =>
@ -210,7 +213,7 @@ using (var db = GetDB())
db.Add(new LiveDataMsg() {Id = "live", Uts = DateTimeOffset.Now, Text = "begin"}, update:true);
});
}
*/
//var t1 = Task.Run(() => Produce());
@ -219,23 +222,28 @@ using (var db = GetDB())
//var t2 = ConsumeAsync();
//Task.WaitAll(t1, t2);
using (var ctx = new AppDbContext())
{
ctx.Database.EnsureCreated();
}
var b = DateTime.Now;
using (var ctx = new AppDbContext())
var builder = new DbContextOptionsBuilder<AppDbContext>();
{
for (var i = 1; i != 1000; ++i)
for (var i = 1; i != 10000; ++i)
{
//{
using (var ctx = new AppDbContext())
{
var s = new LiveDataState {ItemId = i, EcuId = (ushort) (i + 1), Value = (float) (i * 1.0)};
ctx.Add(s);
//Console.WriteLine(ctx.Entry<LiveDataState>(s).Entity.ItemId);
//ctx.SaveChanges();
//}
ctx.SaveChanges();
}
//ctx.SaveChanges();
}
ctx.SaveChanges();
}
Console.WriteLine($"{(DateTime.Now - b).TotalSeconds}");

Loading…
Cancel
Save