Oscar.EntityFrameworkCore.Sql
8.0.14
Requires NuGet 3.6 or higher.
dotnet add package Oscar.EntityFrameworkCore.Sql --version 8.0.14
NuGet\Install-Package Oscar.EntityFrameworkCore.Sql -Version 8.0.14
<PackageReference Include="Oscar.EntityFrameworkCore.Sql" Version="8.0.14" />
<PackageVersion Include="Oscar.EntityFrameworkCore.Sql" Version="8.0.14" />
<PackageReference Include="Oscar.EntityFrameworkCore.Sql" />
paket add Oscar.EntityFrameworkCore.Sql --version 8.0.14
#r "nuget: Oscar.EntityFrameworkCore.Sql, 8.0.14"
#:package Oscar.EntityFrameworkCore.Sql@8.0.14
#addin nuget:?package=Oscar.EntityFrameworkCore.Sql&version=8.0.14
#tool nuget:?package=Oscar.EntityFrameworkCore.Sql&version=8.0.14
Oscar.EntityFrameworkCore.Sql is the EF Core 8 database provider package for ShenTong Oscar database.
Packages
| 包 | 作用 |
|---|---|
Oscar.EntityFrameworkCore.Sql |
EF Core 8 提供程序(本包) |
Oscar.Data.SqlClient |
ADO.NET 驱动,随本包作为依赖自动引入;也直接提供 System.Data.OscarClient.OscarConnection 等类型 |
Usage
Call the UseSql method to choose the Oscar database provider for your DbContext. For example:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSql(
"Server=<host>;Port=2003;Database=<database>;User Id=<user>;Password=<password>;");
}
请把真实凭据放在环境变量、用户机密(
dotnet user-secrets)或部署时的配置里,不要写进源码或示例。
Provider-specific options
optionsBuilder.UseSql(connectionString, builder =>
{
// 未显式 ToTable(..., schema) 的对象都落在这个模式下
builder.UseDefaultSchema("APP");
// 默认 true: 生成不加引号的标识符, 由服务端统一大写化。
// 设为 false: 标识符加双引号, 严格保留原样大小写(模式/表/列名都会按你写的样子落库)。
builder.UseNamedIgnoreCaseEnabled(false);
// 迁移历史表(默认 __EFMigrationsHistory)
builder.MigrationsHistoryTable("__EFMigrationsHistory", "APP");
// 对连接失败、锁等待超时与死锁做重试
builder.EnableRetryOnFailure(maxRetryCount: 3);
});
Modeling example
public class UserContext : DbContext
{
public UserContext(DbContextOptions<UserContext> options) : base(options)
{
}
public DbSet<User> Users { get; set; }
public DbSet<Blog> Blogs { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// 序列: 供默认值 NEXTVAL 使用
modelBuilder.HasSequence<int>("OrderNumbers", schema: "APP").StartsAt(1000).IncrementsBy(5);
modelBuilder.Entity<User>(b =>
{
b.ToTable("Users", "APP");
b.HasKey(u => u.UserId);
b.Property(u => u.Age).HasColumnType("int");
b.Property(u => u.Name).HasColumnType("varchar(128)");
b.Property(u => u.BrithDate).HasColumnType("timestamp");
b.Property(u => u.GenId).HasDefaultValueSql("NEXTVAL(OrderNumbers)");
});
}
}
public class User
{
public int UserId { get; set; } // 自增主键
public int Age { get; set; }
public string Name { get; set; }
public DateTime BrithDate { get; set; }
public int GenId { get; set; }
}
对应的建表语句(GenId 两种写法都可用:计算列或序列默认值):
CREATE TABLE APP.Users (
UserId INT8 AUTO_INCREMENT PRIMARY KEY,
Age INT,
Name VARCHAR(128),
BrithDate TIMESTAMP,
GenId INT DEFAULT (NEXTVAL('APP.OrderNumbers'))
);
批量写入后可用 EF Core 的集合型 DML:
context.Users.Where(u => u.Age < 18)
.ExecuteUpdate(s => s.SetProperty(u => u.Name, "minor"));
context.Users.Where(u => u.BrithDate < new DateTime(2000, 1, 1))
.ExecuteDelete();
Migrations and reverse engineering
dotnet ef migrations add Initial
dotnet ef database update
# 从已有库反向生成模型
dotnet ef dbcontext scaffold "<connection-string>" Oscar.EntityFrameworkCore.Sql --schema APP
反向工程只读取 INFO_SCHEM.V_SYS_* 目录视图(它们由服务端的权限谓词过滤),因此普通数据库账号也能执行 dbcontext scaffold,结果是该账号有权限访问的那部分对象;不需要 sysdba。全文索引会被还原成 IsFullText() / HasFullTextAnalyzer(...) 等 fluent 调用。
Getting started with EF Core
See Getting started with EF Core for more information about EF NuGet packages, including which to install when getting started.
Additional documentation
See ShenTong Oscar Database EF Core Database Provider for more information about the features of this database provider.
Feedback
If you encounter a bug or issues with this package, you can open a GitHub issue. For more details, see documents.
| 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.18)
- Oscar.Data.SqlClient (>= 4.2.40)
- System.Formats.Asn1 (>= 8.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 8.0.14 | 84 | 11/4/2026 |
| 8.0.13 | 99 | 10/29/2026 |
| 8.0.12 | 91 | 10/29/2026 |
| 8.0.10 | 177 | 4/24/2026 |
| 8.0.9 | 196 | 1/28/2026 |
| 8.0.8 | 158 | 1/6/2026 |
| 8.0.7 | 161 | 1/6/2026 |
| 8.0.6 | 254 | 9/23/2025 |
| 8.0.5 | 270 | 9/10/2025 |
| 8.0.4 | 260 | 9/5/2025 |
| 8.0.3 | 265 | 9/4/2025 |
| 8.0.2 | 254 | 9/2/2025 |
| 8.0.0 | 248 | 7/31/2025 |
| 7.0.0 | 279 | 7/16/2024 |
| 6.0.2 | 139 | 6/9/2026 |
| 6.0.1 | 259 | 5/29/2024 |
| 6.0.0 | 504 | 10/13/2022 |