简体   繁体   English

C# Entity Framework Core 写入 sqlite_sequence 表

[英]C# Entity Framework Core write into sqlite_sequence Table

I´ve got a SQLite-Db and using EF Core.我有一个 SQLite-Db 并使用 EF Core。 We need to save a sequence of DateTimes, where each time a continously process calls the controller the timespan from last request to DateTime.Now is the process relevant data.我们需要保存一系列 DateTimes,其中每次连续进程调用 controller 从上次请求到 DateTime.Now 的时间跨度是进程相关数据。

Therefor I wanted to save the last DateTime into the sequence table of SQLite but on Database.EnsureCreated() I get the following exception SQLite Error 1: 'object name reserved for internal use: sqlite_sequence'.因此,我想将最后一个 DateTime 保存到 SQLite 的序列表中,但是在Database.EnsureCreated()上,我得到以下异常SQLite Error 1: 'object name reserved for internal use: sqlite_sequence'. I think its because EF tries to create the table but should not.我认为这是因为 EF 试图创建表但不应该。

Does someone know how to write custom data into this table or someone has a better way to store a single DateTime within the Database?有人知道如何将自定义数据写入此表或有人有更好的方法在数据库中存储单个 DateTime 吗?

        I will give your this approach for ef to sql lite for your db context and using this will easy to store any data (Db configurations is used to configure properties in the table).
    
            public class ApplicationContext : DbContext
                {
                    protected override void 
 OnConfiguring(DbContextOptionsBuilder optionsBuilder)
                    {
                        optionsBuilder.UseSqlite("Filename=database.db", options =>
                        {
                            
        options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName);
                        });
                        if (!optionsBuilder.IsConfigured)
                        {
                            optionsBuilder.UseSqlite("Filename=database.db");
                        }
                        base.OnConfiguring(optionsBuilder);
                    }
                    protected override void OnModelCreating(ModelBuilder modelBuilder)
                    {
                        modelBuilder.ApplyConfiguration(new SettingsDbConfiguration());
                        base.OnModelCreating(modelBuilder);
                    }
                    
                    public DbSet<BaseSettings> Settings { get; set; }
               
    
     }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM