Aicrosoft.DataAccess.EntityFrameworkCore 8.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Aicrosoft.DataAccess.EntityFrameworkCore --version 8.2.0                
NuGet\Install-Package Aicrosoft.DataAccess.EntityFrameworkCore -Version 8.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Aicrosoft.DataAccess.EntityFrameworkCore" Version="8.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Aicrosoft.DataAccess.EntityFrameworkCore --version 8.2.0                
#r "nuget: Aicrosoft.DataAccess.EntityFrameworkCore, 8.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Aicrosoft.DataAccess.EntityFrameworkCore as a Cake Addin
#addin nuget:?package=Aicrosoft.DataAccess.EntityFrameworkCore&version=8.2.0

// Install Aicrosoft.DataAccess.EntityFrameworkCore as a Cake Tool
#tool nuget:?package=Aicrosoft.DataAccess.EntityFrameworkCore&version=8.2.0                

Aicrosoft.DataAccess.EntityFrameworkCore

本库引用了 Aicrosoft.DataAccess ,使得可以直接通过IOC取得位于该库的 实现了接口IRepository<User, int>的实例,来操作相关Db。

重要接口

IRepository<TEntity, TKey> 针对DbContext中的某个表的实体的存储操作

  • TEntity 传入的实体
  • TKey 实体的Key

ICommonRepository

  • 无关于实体的仅和DB有关的相关操作

Note

  • 连接数是与 DbContext 的实例数量相关的。

How To Use

  1. Add Entity For Table
public class Phone : Entity<Guid>
{
    public string? PhoneNumber { get; set; }

}

public class Employe : Entity<int>
{
    public string? Name { get; set; }

    public List<Phone>? Phones { get; set; }
}
  1. First Create XXDbContext for Database
public class SqlServerSampleDbContext : DbContext
{
    //可初始化连接串
    public SqlServerSampleDbContext(DbContextOptions options) : base(options) { }

    public DbSet<Employe>? Employes { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        ////它会重重通过DbContextOptions传进来的连接串。
        // optionsBuilder.UseSqlServer("MyConnectionString")
    }
}

  1. Migration and update database 不必是在可启动的项目里,只要是在有DbContext的项目中即可。
# Install
dotnet tool install --global dotnet-ef

# update
dotnet tool update --global dotnet-ef

# cd the project dir
## 专门用于迁移Sqliter的Client端
cd F:\Aicrosoft\ProjectTemplates\ProjectTemplates\Developing\SuperJobs\SqliteDbSampeMigrator

# use the tools on a specific project || 用Nuget包安装到你想生成的项目里
# 注意:版本必须与DbContext引用的版本一致。
dotnet add package Microsoft.EntityFrameworkCore.Design -v 8.0.7
# Install-Package Microsoft.EntityFrameworkCore.Design -Version 8.0.7

# add migration
## 创建一个新的迁移脚本,记录当前模型与数据库之间的差异。
dotnet ef migrations add init --context SqliteSampleDbContextMig

# Updates the database to the last migration or to a specified migration.
## 将所有未应用的迁移应用到数据库上。
dotnet ef database update --context SqliteSampleDbContext


## 显示所有可用的迁移,包括已应用和未应用的迁移。
dotnet ef migrations list

## 回滚最近应用的迁移。
dotnet ef database update <MigrationName>

## 生成SQL脚本来创建数据库和所有迁移。
dotnet ef migrations script
  1. Use by IEFRepository
  var rep = serviceProvider.GetRequiredService<IRepository<User, int>>();
  rep.Add(new User { Name = "Test" });
  var rst = rep.SaveChanges();


Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Aicrosoft.DataAccess.EntityFrameworkCore:

Package Downloads
Aicrosoft.DataAccess.DbMigration

Extensions of Aicrosoft Ltd.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.5.0 96 10/12/2024
8.3.0 105 9/10/2024
8.2.0 96 8/7/2024
8.1.0 98 7/16/2024
8.1.0-dev.240716.12 49 7/16/2024
6.4.0 314 11/20/2023
6.3.2 150 11/1/2023
6.2.1 163 8/25/2023
6.1.7 195 7/25/2023
6.1.6 163 5/17/2023