国产aaa免费视频国产,日韩一区二区不卡中文字幕,日产精品一二三四区国产,69频道,精品亚洲成a人片在线观看,伊人福利视频,欧美线在线精品观看视频

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

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

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

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

·                  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

添加測試模型,生成基架

    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ù)庫生成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連接字符串,同時把program.cs中的也換過來,如下:

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.")));

訪問地址:https://localhost:7202/posts

報如下錯誤:

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


重新訪問地址: https://localhost:7202/posts



下拉加載更多評論
最新評論
暫無!