【EF Core】Code first


简介

前期环境

Visual Studio 2022
.net framework 4.7.2
Sqlite3
Navicat 15

CodeFirst的三种方式

一、使用新数据库的CodeFirst

查看:https://learn.microsoft.com/zh-cn/ef/ef6/modeling/code-first/workflows/existing-database

查看:https://www.cnblogs.com/dotnet261010/p/7119351.html

 

二、使用现有的数据库的CodeFirst

1. 创建应用程序

为简单起见由于System.Data.SQLite不支持.net5.0及以上的所以只能新建一个“控制台应用程序(.net framework)”来操作 CodeFirst,我们将生成一个使用 Code First 进行数据访问的基本控制台应用程序:

  • 打开 Visual Studio
  • “文件”->“新建”->“项目…”
  • 从左侧菜单中选择“Windows”并选择“控制台应用程序”
  • 输入 CodeFirstExistingDatabaseSample 作为名称
  • 选择“确定”

 

 

2、安装必要的插件

System.Data.SQLite DDEX提供程序不支持Visual Studio 2017和2019,本文介绍如何使用EF6的“SQLite Toolbox” DDEX(这是VS的一个插件)提供程序在Visual Studio 2017/2019中使用SQLite和Entity Framework 6。

首先下载SQLite Toolbox插件:

1)安装SQLite Toolbox插件:https://www.vsixgallery.com/extension/41521019-e4c7-480c-8ea8-fc4a2c6f50aa

2)然后在Nugut Vs2022下载sqlite for netframework的驱动程序:System.Data.sQLite

 

添加完成后

 

 剩下查看:https://learn.microsoft.com/zh-cn/ef/ef6/modeling/code-first/workflows/existing-database

三、使用迁移的数据库的CodeFirst

查看:实操EFCore的CodeFirst(Migration)

查看:https://learn.microsoft.com/zh-cn/ef/ef6/modeling/code-first/migrations/automatic

posted @ 2024-04-11 01:42  小林野夫  阅读(28)  评论(0编辑  收藏  举报
原文链接:https://www.cnblogs.com/cdaniu/