我的dbcontext.users.dadd有问题

时间:2019-05-19 10:06:47

标签: c# sqlite discord.net

我正在制造一个不和谐的机器人,我正在编写一个保存作业的函数,但是它不能像var那样添加新作业。

   public static async Task SaveJobs(string nosaukums, string apraksts, string statuss)
    {
        using (var DBcontext = new SQLiteDBcontext())
        {
            var add = new Jobs
            {
                Apraksts = apraksts,
                Notikums = nosaukums,
                Statuss = statuss,
                Darbinieki = ""
            };

            DBcontext.Jobs.Add(add);
            await DBcontext.SaveChangesAsync();
        }

    }

Microsoft.Data.Sqlite.SqliteException(0x80004005):SQLite错误1:'没有这样的表:Users'。    在Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc,sqlite3 db)    在Microsoft.Data.Sqlite.SqliteCommand.PrepareAndEnumerateStatements(Stopwatch计时器)+ MoveNext()    在Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior行为)    在Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection连接,DbCommandMethod executeMethod,IReadOnlyDictionary 2 parameterValues) at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary 2参数值)处    在Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable 1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable 1.Enumerator.MoveNext()    在Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider._TrackEntities [TOut,TIn](IEnumerable 1 results, QueryContext queryContext, IList 1EntityTrackingInfos,IList 1 entityAccessors)+MoveNext() at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor 1.EnumeratorExceptionInterceptor.MoveNext()    在System.Collections.Generic.List 1.AddEnumerable(IEnumerable 1上可枚举)    在System.Linq.Enumerable.ToList [TSource](IEnumerable`1源)处    位于botLAPD.Core.Data.Data.SaveUser(UInt64 IDofUser)在C:\ Users \ LIAR \ source \ repos \ botLAPD \ botLAPD \ Core \ Data \ Data.cs:第18行

try
                {
**LINE 18**        var check = DBcontext.Users.Where(x => x.IDuser == IDofUser).ToList();
                    if (check == null)
                    {
                        Console.WriteLine("33333333333333333333333333333333333333333333333");
                        DBcontext.Users.Add(new Users
                        {
                            IDuser = IDofUser,
                            Apraksts = " ",
                            Notikums = " ",
                            Statuss = " "
                        });
                        Console.WriteLine("awdawdawdaw3e12415124123123123123123123123");
                    }
                    else
                    {
                        Users Current = DBcontext.Users.Where(x => x.IDuser == IDofUser).FirstOrDefault();
                        DBcontext.Users.Update(Current);
                        Console.WriteLine("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
                    }
                    await DBcontext.SaveChangesAsync();
                    Console.WriteLine("BEIGAS");
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex);
                Console.WriteLine("BEIGAS");
                }

0 个答案:

没有答案