一区在线电影,国产在线首页,中文字幕精,天天爽天天射,夜色99,日韩国产成人av,伊人久久综合视频

威勢(shì)網(wǎng)絡(luò),為您的企業(yè)和團(tuán)隊(duì)注入互聯(lián)網(wǎng)活力!
服務(wù)熱線:138-9741-0341

[原創(chuàng)]MVC引入SqlLiet數(shù)據(jù)庫(kù)

發(fā)布日期:2022/9/1 作者: 瀏覽:1122

引入SQL數(shù)據(jù)庫(kù)組件

·                  Microsoft.EntityFrameworkCore.Sqlite

·                 

官方參考鏈接:https://docs.microsoft.com/zh-cn/ef/core/providers/sqlite/?tabs=dotnet-core-cli

SQLLITE連接字符串:https://docs.microsoft.com/zh-cn/dotnet/standard/data/sqlite/connection-strings

添加測(cè)試模型,生成基架

    public class Blog

    {

        public int BlogId { get; set; }

        public string Name { get; set; }

        public string Url { get; set; }

        public ICollection<Post> Posts { get; set; }

    }

    public class Post

    {

        public int PostId { get; set; }

        public string Title { get; set; }

        public string Content { get; set; }

        public int BlogId { get; set; }

}

默認(rèn)用SQLSERVER數(shù)據(jù)庫(kù)生成appsetting.json

  "ConnectionStrings": {

    //"db": "Server=(localdb)\\mssqllocaldb;Database=SqlLiteMVC.Data;Trusted_Connection=True;MultipleActiveResultSets=true",

    "db": "Data Source=mydb.db;Cache=Shared;Default Timeout=30"

  }

sqlserver替換成sqllite連接字符串,同時(shí)把program.cs中的也換過(guò)來(lái),如下:

builder.Services.AddDbContext<db>(options =>

    //options.UseSqlServer(builder.Configuration.GetConnectionString("db") ?? throw new InvalidOperationException("Connection string 'db' not found.")));

    options.UseSqlite(builder.Configuration.GetConnectionString("db") ?? throw new InvalidOperationException("Connection string 'db' not found.")));

訪問(wèn)地址:https://localhost:7202/posts

報(bào)如下錯(cuò)誤:

An unhandled exception occurred while processing the request.

SqliteException: SQLite Error 1: 'no such table: Post'.

Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(int rc, sqlite3 db)

在包管理命令中執(zhí)行:Add-Migration Init


重新訪問(wèn)地址: https://localhost:7202/posts



下拉加載更多評(píng)論
最新評(píng)論
暫無(wú)!