Aicrosoft.DataAccess.EntityFrameworkCore
8.2.0
There is a newer version of this package available.
See the version list below for details.
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Aicrosoft.DataAccess.EntityFrameworkCore
本库引用了 Aicrosoft.DataAccess
,使得可以直接通过IOC取得位于该库的 实现了接口IRepository<User, int>
的实例,来操作相关Db。
重要接口
IRepository<TEntity, TKey> 针对DbContext中的某个表的实体的存储操作
- TEntity 传入的实体
- TKey 实体的Key
ICommonRepository
- 无关于实体的仅和DB有关的相关操作
Note
- 连接数是与 DbContext 的实例数量相关的。
How To Use
- 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; }
}
- 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")
}
}
- 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
- Use by IEFRepository
var rep = serviceProvider.GetRequiredService<IRepository<User, int>>();
rep.Add(new User { Name = "Test" });
var rst = rep.SaveChanges();
Product | Versions 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.
-
net8.0
- Aicrosoft.DataAccess (>= 8.2.0)
- Microsoft.EntityFrameworkCore (>= 8.0.7)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.7)
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.