Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 特例 _HResult=-2147467259 _message=SQL逻辑错误或缺少数据库没有这样的表:Blogs HResult=-2147467259 IsTransient=false Message=SQL逻辑错误或缺少数据库没有这样的表:Blogs Source=System.Data.SQLite 错误代码=1 堆栈跟踪: 在System.Data.SQLite.SQLite3.Prepare(SQLiteConnection,字符串 strSql、SQLiteStatement-previous、UInt32 timeoutMS、String和stremain) 在System.Data.SQLite.SQLiteCommand.BuildNextCommand()中 在System.Data.SQLite.SQLiteCommand.GetStatement(Int32索引)处 位于System.Data.SQLite.SQLiteDataReader.NextResult()处 在System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, 命令(行为) 在System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior)中 (行为) 在System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader(CommandBehavior)中 (行为) 位于System.Data.Common.DbCommand.ExecuteReader(CommandBehavior) 在System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.c__DisplayClassb.b__8()中 在System.Data.Entity.Infrastructure.InternalDispatcher.Dispatcher中 操作,TInterceptionContext拦截context,操作1 正在执行,操作1已执行) 在System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand 命令,DBCommandInterceptOnContext(InterceptOnContext) 位于System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior (行为) 位于System.Data.Common.DbCommand.ExecuteReader(CommandBehavior) 在System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(字典)中 标识值,列表'1生成值) 位于System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()处 内部异常:_C#_Entity Framework_Sqlite_Ef Code First - Fatal编程技术网

C# 特例 _HResult=-2147467259 _message=SQL逻辑错误或缺少数据库没有这样的表:Blogs HResult=-2147467259 IsTransient=false Message=SQL逻辑错误或缺少数据库没有这样的表:Blogs Source=System.Data.SQLite 错误代码=1 堆栈跟踪: 在System.Data.SQLite.SQLite3.Prepare(SQLiteConnection,字符串 strSql、SQLiteStatement-previous、UInt32 timeoutMS、String和stremain) 在System.Data.SQLite.SQLiteCommand.BuildNextCommand()中 在System.Data.SQLite.SQLiteCommand.GetStatement(Int32索引)处 位于System.Data.SQLite.SQLiteDataReader.NextResult()处 在System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, 命令(行为) 在System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior)中 (行为) 在System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader(CommandBehavior)中 (行为) 位于System.Data.Common.DbCommand.ExecuteReader(CommandBehavior) 在System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.c__DisplayClassb.b__8()中 在System.Data.Entity.Infrastructure.InternalDispatcher.Dispatcher中 操作,TInterceptionContext拦截context,操作1 正在执行,操作1已执行) 在System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand 命令,DBCommandInterceptOnContext(InterceptOnContext) 位于System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior (行为) 位于System.Data.Common.DbCommand.ExecuteReader(CommandBehavior) 在System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(字典)中 标识值,列表'1生成值) 位于System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()处 内部异常:

C# 特例 _HResult=-2147467259 _message=SQL逻辑错误或缺少数据库没有这样的表:Blogs HResult=-2147467259 IsTransient=false Message=SQL逻辑错误或缺少数据库没有这样的表:Blogs Source=System.Data.SQLite 错误代码=1 堆栈跟踪: 在System.Data.SQLite.SQLite3.Prepare(SQLiteConnection,字符串 strSql、SQLiteStatement-previous、UInt32 timeoutMS、String和stremain) 在System.Data.SQLite.SQLiteCommand.BuildNextCommand()中 在System.Data.SQLite.SQLiteCommand.GetStatement(Int32索引)处 位于System.Data.SQLite.SQLiteDataReader.NextResult()处 在System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, 命令(行为) 在System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior)中 (行为) 在System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader(CommandBehavior)中 (行为) 位于System.Data.Common.DbCommand.ExecuteReader(CommandBehavior) 在System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.c__DisplayClassb.b__8()中 在System.Data.Entity.Infrastructure.InternalDispatcher.Dispatcher中 操作,TInterceptionContext拦截context,操作1 正在执行,操作1已执行) 在System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand 命令,DBCommandInterceptOnContext(InterceptOnContext) 位于System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior (行为) 位于System.Data.Common.DbCommand.ExecuteReader(CommandBehavior) 在System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(字典)中 标识值,列表'1生成值) 位于System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()处 内部异常:,c#,entity-framework,sqlite,ef-code-first,C#,Entity Framework,Sqlite,Ef Code First,我猜你们已经改变了你们的模式,或者你们在第一次创建数据库之后添加了博客。 在BloggingContext的Constractor中写下: Database.SetInitializer<BloggingContext>(new DropCreateDatabaseIfModelChanges<BloggingContext>()); Database.SetInitializer(新的DropCreateDatabaseIfModelChanges()); 希望它能

我猜你们已经改变了你们的模式,或者你们在第一次创建数据库之后添加了博客。 在BloggingContext的Constractor中写下:

Database.SetInitializer<BloggingContext>(new DropCreateDatabaseIfModelChanges<BloggingContext>());
Database.SetInitializer(新的DropCreateDatabaseIfModelChanges());

希望它能工作。

实际的错误消息是“没有这样的表:博客”。是的,我看到了。在SaveChanges()之前,上下文确实有博客的本地副本。此错误消息是否表示数据库文件在创建时没有博客信息?我刚刚注意到数据库文件是在创建上下文之前创建的。我原以为在创建上下文时会创建数据库文件。我正在尝试在应用程序中创建和修改数据库文件。它不是以前创建的。那么为什么会出现此异常?除非EF试图删除某些内容。如果提供程序不支持删除数据库,请尝试迁移。我试图在应用程序中首先使用代码创建数据库。这是一个我允许用户创建项目新数据库的应用程序示例。上面的代码示例是我尝试先使用代码创建一个新的数据库文件,然后向其中添加项目。鉴于我得到的错误,我一定是做了一些错误的代码。是否可以先使用代码创建数据库,然后向其中添加项目?是的。我以前也有过类似的问题。正因为如此,我说也许你改变了你的模型,甚至是名字上的一点小小的改变。所以,如果这是你第一次运行你的程序,问题就出在别的地方。使用“DropCreateDatabaseIfModelChanges”代替“DropCreateDatabaseAlways”添加此程序集:使用System.ComponentModel.DataAnnotation.Schema;上面的博客类写了这个。BlogId上面的[Table(“Blogs”)]写下以下内容:[Key]在数据库上设置断点。SetInitializer。。运行程序。在断点-->F10-->处,右键单击数据库word-->QuickWatch。查找连接字符串。也许它和你给它的不一样。
Database.SetInitializer<BloggingContext>(new DropCreateDatabaseIfModelChanges<BloggingContext>());