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
                    
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="Oscar.EntityFrameworkCore.Sql" Version="8.0.14" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oscar.EntityFrameworkCore.Sql" Version="8.0.14" />
                    
Directory.Packages.props
<PackageReference Include="Oscar.EntityFrameworkCore.Sql" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Oscar.EntityFrameworkCore.Sql --version 8.0.14
                    
#r "nuget: Oscar.EntityFrameworkCore.Sql, 8.0.14"
                    
#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.
#:package Oscar.EntityFrameworkCore.Sql@8.0.14
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Oscar.EntityFrameworkCore.Sql&version=8.0.14
                    
Install as a Cake Addin
#tool nuget:?package=Oscar.EntityFrameworkCore.Sql&version=8.0.14
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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