标签: sqlite

无法创建类型为“MyContext”的对象。对于设计时支持的不同模式

我在 .NET Core 上有 ConsoleApplication 并且我将我的 DbContext 添加到依赖项中,但是我有一个错误:

无法创建类型为“MyContext”的对象。有关设计时支持的不同模式,请参阅https://go.microsoft.com/fwlink/?linkid=851728

我添加了:var context = host.Services.GetRequiredService<MyContext>();private readonly DbContextOptions<MyContext> _opts;还在我的帖子类中添加了:

using (MyContext db = new MyContext(_opts))
 {
 db.Posts.Add(postData);
 db.SaveChanges();
 }
Run Code Online (Sandbox Code Playgroud)

这是我添加服务的方式:

.ConfigureServices((context, services) =>
                {
                    services.Configure<DataOptions>(opts =>
                        context.Configuration.GetSection(nameof(DataOptions)).Bind(opts));
                    services.AddDbContext<MyContext>((provider, builder) =>
                        builder.UseSqlite(provider.GetRequiredService<IOptions<DataOptions>>().Value.ConnectionString));
Run Code Online (Sandbox Code Playgroud)

这是我的上下文:

public sealed class MyContext : DbContext
    {
        private readonly DbContextOptions<MyContext> _options;

        public DbSet<PostData> Posts { get; set; }
        public DbSet<VoteData> Votes { get; set; }


        public MyContext(DbContextOptions<MyContext> options) : base(options)
        {
            _options = options;
        }

        protected …
Run Code Online (Sandbox Code Playgroud)

c# sqlite datacontext entity-framework .net-core

16
推荐指数
4
解决办法
1万
查看次数

Android Q:范围存储中的 SQLite 数据库

在 Android Q 中引入了新的Scoped 存储功能,它说:

默认情况下,面向 Android 10(API 级别 29)及更高版本的应用会获得对外部存储或范围存储的范围访问。此类应用程序只能访问外部存储上的应用程序特定目录,以及应用程序创建的特定类型的媒体。

我有我的应用程序,它在外部存储上创建 SQLite 数据库,这样当应用程序卸载数据库时,数据库仍然存在,以后可以用作恢复或在 Android 设备之外使用(假设在 PC 中)

我应该如何实现与 Android Q 相同的效果?更准确地说,如果数据库存储在外部公共目录中 - 如何使用标准读取此数据库SQLiteOpenHelper

java sqlite android kotlin android-sqlite

16
推荐指数
1
解决办法
1062
查看次数

移除应用程序时,Sqlite数据库会发生什么

我是Android编程的新手,并试图围绕这一点,只是为了让自己清楚自己的工作方式.

在Android应用程序中创建Sqlite数据库时,数据库存储在何处?应用程序删除后会删除吗?任何有关此信息都将有助于理解来自Web开发背景的人们的Android编程.

sqlite android

15
推荐指数
1
解决办法
9821
查看次数

如何在flutter中将图像数据保存到sqflite数据库以实现持久化

我正在构建一个 Flutter 应用程序,我希望将数据保持在离线状态。

我正在使用相机或图库图像选择器捕获图像,并且能够将该图像存储到File image变量中。

File _avatarImg;

void _getImage(BuildContext context, ImageSource source) {
    ImagePicker.pickImage(
      source: source,
      maxWidth: 400.0,
      maxHeight: 400.0,
    ).then((File image) {
      _avatarImg = image;
    });
  }
Run Code Online (Sandbox Code Playgroud)

这非常有效,但我的问题是,我将如何存储此图像以保持持久性?我是否应该在图像所在的手机中存储指向本地媒体目录的字符串链接?如果是这样,我会担心图像是否被用户意外删除。或者我是否将图像本身存储到 BLOB 中的数据库中?这方面的最佳做法是什么?

database sqlite dart flutter

15
推荐指数
2
解决办法
2万
查看次数

为什么android studio 4.2 canary 13中没有android数据库检查器工具?

我正在测试 Android Studio 4.2 canary 13 和 SQLite。

这篇文章中,您可以阅读“使用 Android Studio 4.1 Canary 6及更高版本,您可以使用新的数据库检查器检查、查询和修改应用程序的数据库。 ”和“要开始使用,请将您的应用程序部署到运行API 级别 26的设备上或更高版本,然后从菜单栏中选择查看 > 工具窗口 > 数据库检查器 ”,但是正如您在照片中看到的,此选项在 Android Studio 4.2 上不可用,为什么?

测试应用的 API 为 30。

在此处输入图片说明

更新:

在使用这个版本的 Android Studio(4.2) 之前,我的机器(Windows 10 X64)上安装了 Android Studio 4.0.1,我卸载了它。

sqlite android android-studio

15
推荐指数
1
解决办法
2117
查看次数

无法从程序集“Microsoft.EntityFrameworkCore”加载类型“Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer”,

我有一个使用 EF Core 的 ASP.NET Core 3.1 Web API 应用程序。这是我在类的ConfigureServices方法中的配置Startup

services.AddDbContext<ApplicationContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("AppConn")));
Run Code Online (Sandbox Code Playgroud)

上述配置已测试并适用于 SQL Server 数据库。

然后我在成功安装它的包后切换到使用 Sqlite。

services.AddDbContext<ApplicationContext>(options =>
     options.UseSqlite("Data Source=sqlitedemo.db"));
Run Code Online (Sandbox Code Playgroud)

但是当我尝试添加 EF 迁移时

add-migration initial -context ApplicationContext
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

System.Reflection.TargetInvocationException:调用的目标已抛出异常。

System.TypeLoadException: 无法从程序集“Microsoft.EntityFrameworkCore, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60”中加载类型“Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer”。

在 Microsoft.EntityFrameworkCore.Design.OperationExecutor..ctor(IOOperationReportHandler reportHandler, IDictionary args)
--- 内部异常堆栈跟踪结束 ---
在 System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean 构造函数, Boolean wrapExceptions)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfoculture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfoculture)
at System .Activator.CreateInstance(类型类型,BindingFlags bindingAttr,Binder …

c# sqlite entity-framework-core

15
推荐指数
6
解决办法
2万
查看次数

Microsoft.Data.SQLite:找不到库 e_sqlite3

我使用 Microsoft.Data.Sqlite 5.0.2 的 ASP.NET MVC (.Net Framework 4.7.2) Web 应用程序在以下行崩溃(在调试 IIS Express 和 Windows 10 中本地 IIS 上的 app.publish 中):

SqliteConnection dbConn = new SqliteConnection("Data Source=test.db");
Run Code Online (Sandbox Code Playgroud)

抛出的异常:

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.
  Source=Microsoft.Data.Sqlite
  StackTrace:
   at Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)
   at sqliteTest.Controllers.ValuesController.Get() in C:\Users\FaqeerHussain\source\repos\sqliteTest\sqliteTest\Controllers\ValuesController.cs:line 16
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.<GetExecutor>b__2(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
TargetInvocationException: …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net sqlite iis

15
推荐指数
3
解决办法
2万
查看次数

Docker Alpine:在为 ARM 构建映像时无法选择软件包:python(没有此类软件包)

我有使用 SQLite 数据库的 Node.js 应用程序。要在 ARM 架构上使用它,我需要构建 sqlite3 二进制文件,因此在构建 Docker 映像时需要一些包。

这是我的 Dockerfile:

FROM node:14-alpine as builder

WORKDIR /app

COPY package*.json ./

RUN apk update \
    && apk --no-cache --virtual build-dependencies add python make g++ \
    && npm install --production

COPY . .    

RUN mkdir -p ./public ./data \
    && cd ./client \
    && npm install --production \
    && npm run build \
    && cd .. \
    && mv ./client/build/* ./public \
    && rm -rf ./client \
    && apk del …
Run Code Online (Sandbox Code Playgroud)

linux sqlite docker dockerfile alpine-linux

15
推荐指数
2
解决办法
3万
查看次数

如何修复运行 npx knex migrate:make test 时找不到模块“@vscode/sqlite3”

执行的时候npx knex migrate:make弹出这个错误

Using environment: development
Knex: run
$ npm install sqlite3 --save
Cannot find module '@vscode/sqlite3'
Require stack:
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\dialects\sqlite3\index.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\knex-builder\internal\config-resolver.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\knex-builder\Knex.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\index.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\knex.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\bin\cli.js
Error: Cannot find module '@vscode/sqlite3'
Require stack:
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\dialects\sqlite3\index.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\knex-builder\internal\config-resolver.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\knex-builder\Knex.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\index.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\knex.js
- C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\bin\cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Client_SQLite3._driver (C:\Users\thenu\Desktop\New folder\sqlite\node_modules\knex\lib\dialects\sqlite3\index.js:32:12) …
Run Code Online (Sandbox Code Playgroud)

sqlite node.js

15
推荐指数
2
解决办法
9299
查看次数

MissingGreenlet:greenlet_spawn 尚未被调用

我正在尝试获取一对多关系中匹配的行数。当我尝试时parent.children_count我得到:

sqlalchemy.exc.MissingGreenlet:greenlet_spawn尚未被调用;不能在这里调用await_only()。是否在意想不到的地方尝试了 IO?(此错误的背景位于:https ://sqlalche.me/e/14/xd2s )

我添加了expire_on_commit=False但仍然遇到相同的错误。我怎样才能解决这个问题?

import asyncio
from uuid import UUID, uuid4
from sqlmodel import SQLModel, Relationship, Field
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession

class Parent(SQLModel, table=True):
    id: UUID = Field(default_factory=uuid4, primary_key=True)
    children: list["Child"] = Relationship(back_populates="parent")
    @property
    def children_count(self):
        return len(self.children)

class Child(SQLModel, table=True):
    id: UUID = Field(default_factory=uuid4, primary_key=True)
    parent_id: UUID = Field(default=None, foreign_key=Parent.id)
    parent: "Parent" = Relationship(back_populates="children")

async def main():
    engine = create_async_engine("sqlite+aiosqlite://")
    async with engine.begin() as conn:
        await conn.run_sync(SQLModel.metadata.create_all)

    async with AsyncSession(engine) as …
Run Code Online (Sandbox Code Playgroud)

python sqlite sqlalchemy python-asyncio sqlmodel

15
推荐指数
1
解决办法
2万
查看次数