Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.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# 如何定义数据库上下文_C#_Sqlite_Visual Studio Code_.net Core - Fatal编程技术网

C# 如何定义数据库上下文

C# 如何定义数据库上下文,c#,sqlite,visual-studio-code,.net-core,C#,Sqlite,Visual Studio Code,.net Core,我试图继续介绍如何将.NET Core与SQLite3和VSCode一起使用,但没有明确说明什么是MvcMovieContext 我知道这是一个db上下文,可以从中调用数据库,但是我如何定义它呢 在我的startup.cs中,我有 public void ConfigureServices(IServiceCollection services) { services.AddMvc(); // Add the whole configuration object here

我试图继续介绍如何将.NET Core与SQLite3和VSCode一起使用,但没有明确说明什么是
MvcMovieContext

我知道这是一个db上下文,可以从中调用数据库,但是我如何定义它呢

在我的startup.cs中,我有

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();

    // Add the whole configuration object here
    services.AddSingleton<IConfiguration>(Configuration);

    services.AddDbContext<DBContext>(options => 
        options.UseSqlite("Data Source=LogonChecker.db"));
}
public void配置服务(IServiceCollection服务)
{
services.AddMvc();
//在此处添加整个配置对象
services.AddSingleton(配置);
services.AddDbContext(选项=>
options.UseSqlite(“数据源=LogonChecker.db”);
}
但我当然明白

'找不到类型或命名空间名称'DBContext'(是否缺少using指令或程序集引用?)


所以我的问题是-我该怎么办?只需声明一个空的
DBContext
类?我只想创建一个极其简单的应用程序,将数据存储在sqlite数据库中。非常感谢您提供的任何帮助

下面的教程假定您对Entity Framework(DbContext类的来源)有一定的了解。我将遵循这一点,在.NET core上启动并运行EF。

您对实体框架做了哪些研究?(注意字母大小写)是使用实体框架数据库映射的基类。配置中的类型参数需要在项目中的某个地方定义。如果要使用Sqlite,首先需要添加提供程序。可能要从这里开始: