跳到正文
cccskills
免费在 GitHub 公开

migrating-oracle-to-postgres-data-access-code

Migrate the database access layer of a .NET/C# application from Oracle to PostgreSQL with Npgsql. Update packages, connection settings, parameter types, SQL, and stored procedure calls, then build the copied project and track completed migration tasks.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

Migrates .NET/C# data access code from Oracle to PostgreSQL (Npgsql). Replaces Oracle NuGet packages, rewrites OracleConnection/OracleCommand/OracleDataReader usage, fixes DbType mappings, updates stored procedure invocation patterns, and adapts connection string configuration. Use when migrating the application code layer of a .NET project during an Oracle-to-PostgreSQL database migration.

集成工具PostgreSQL
查看安装方法

适用场景

  • Migrate C# database access from Oracle to PostgreSQL
  • Replace Oracle packages and connection settings
  • Review parameter types and stored procedure calls
  • Adapt EF Core configuration for PostgreSQL

包含的文件(1)

  • SKILL.md7.9 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Migrating .NET Data Access Code from Oracle to PostgreSQL

Migrate the C# data access layer of a single .Postgres-copy project from Oracle (Oracle.ManagedDataAccess) to PostgreSQL (Npgsql). Work item by item through Reports/{ProjectName}/MigrationChecklist.md.

Prerequisites

  • The .Postgres project copy exists (created in Phase 5 setup).
  • Reports/{ProjectName}/MigrationChecklist.md exists and is the source of truth for what to change.
  • Reports/{ProjectName}/OracleRiskAnalysis.md exists for cross-referencing behavioral differences.

Workflow

Progress:
- [ ] Step 1: Replace NuGet packages
- [ ] Step 2: Update connection string configuration
- [ ] Step 3: Rewrite ADO.NET type references
- [ ] Step 4: Fix DbType mappings
- [ ] Step 5: Migrate stored procedure invocation
- [ ] Step 6: Address Oracle-specific SQL and syntax
- [ ] Step 7: Build and verify

Step 1: Replace NuGet packages

In the .csproj of the .Postgres project:

  • Remove: Oracle.ManagedDataAccess.Core, Oracle.EntityFrameworkCore (and any other Oracle.* packages)
  • Add: Npgsql (for ADO.NET) and/or Npgsql.EntityFrameworkCore.PostgreSQL (for EF Core)
  • Keep version pinning consistent with the target .NET version; do not introduce newer package versions than what the solution already uses for similar packages.
  • If System.Data abstractions (IDbConnection, IDbCommand) are used project-wide, the surface-level code may need fewer changes — identify them first.

Step 2: Update connection string configuration

  • Locate the Oracle connection string in appsettings.json, appsettings.{env}.json, web.config, app.config, or environment variable configuration.
  • Replace with a Npgsql-compatible connection string: Host=localhost;Port=5432;Database=mydb;Username=myuser;Password=mypassword
  • Do not hardcode credentials — use the same configuration mechanism already in use (e.g., environment variables, secrets manager, IConfiguration).
  • Update any named connection string keys only if they were Oracle-specific (e.g., OracleConnection). Prefer keeping the same key name to minimize application config changes.

Step 3: Rewrite ADO.NET type references

Replace Oracle-specific ADO.NET types with Npgsql equivalents:

Oracle typeNpgsql replacement
OracleConnectionNpgsqlConnection
OracleCommandNpgsqlCommand
OracleDataReaderNpgsqlDataReader
OracleDataAdapterNpgsqlDataAdapter
OracleParameterNpgsqlParameter
OracleTransactionNpgsqlTransaction
OracleExceptionNpgsqlException
OracleDbTypeNpgsqlDbType (from NpgsqlTypes namespace)

Update using directives accordingly (using Oracle.ManagedDataAccess.Client → using Npgsql).

If the codebase uses IDbConnection/IDbCommand abstractions registered via DI, update only the DI registration and connection string — the consuming code may not need changes.

Step 4: Fix DbType and NpgsqlDbType mappings

Oracle parameter types do not map 1:1 to Npgsql. Review every OracleParameter (now NpgsqlParameter) that sets an explicit type:

Oracle typeNotes
OracleDbType.Varchar2Use NpgsqlDbType.Varchar or omit (Npgsql infers from value)
OracleDbType.ClobUse NpgsqlDbType.Text
OracleDbType.NumberUse NpgsqlDbType.Numeric or NpgsqlDbType.Integer depending on precision
OracleDbType.DateUse NpgsqlDbType.Date (date only) or NpgsqlDbType.Timestamp (if time component used)
OracleDbType.TimeStampUse NpgsqlDbType.Timestamp
OracleDbType.RefCursorUse NpgsqlDbType.Refcursor — see Step 5
OracleDbType.CharUse NpgsqlDbType.Char

For parameters where Oracle inferred the type from the value, Npgsql also infers — explicit type setting is often unnecessary and can be removed.

Step 5: Migrate stored procedure invocation

Oracle and PostgreSQL stored procedure invocation differ significantly:

  • Command type: Retain CommandType.StoredProcedure for function calls. For procedures that use OUT parameters, PostgreSQL requires CommandType.Text with CALL proc_name(...) syntax in some versions of Npgsql — verify against the target Npgsql version.
  • RefCursor handling: Oracle returns ref cursors as output parameters; PostgreSQL returns them differently:
    • For RETURNS TABLE / RETURNS SETOF, use ExecuteReader() directly — no cursor parameter needed.
    • For RETURNS refcursor, call within a transaction, read the cursor name from the output parameter, then issue FETCH ALL IN "<cursor_name>".
    • Remove any Oracle-specific cursor-wrapping code (e.g., OracleRefCursor).
  • OUT parameters: PostgreSQL stored procedures use INOUT or function return values. Verify parameter direction matches the migrated procedure signature.
  • Sequence NEXTVAL: Replace SELECT {SEQUENCE}.NEXTVAL FROM DUAL with SELECT nextval('{sequence_name}').
  • Named parameters: Npgsql uses @param_name; Oracle used :param_name. Update all parameter name prefixes.

Step 6: Address Oracle-specific SQL and C# patterns

Review inline SQL strings and query builders for Oracle-specific constructs and replace:

Oracle constructPostgreSQL replacement
ROWNUM <= nLIMIT n
ROWNUM = 1LIMIT 1
NVL(x, y)COALESCE(x, y)
DECODE(expr, v1, r1, ...)CASE WHEN expr = v1 THEN r1 ... END
SYSDATE / SYSTIMESTAMPNOW() or CURRENT_TIMESTAMP
TO_CHAR(date, fmt)TO_CHAR(date, fmt) (mostly compatible; verify format strings)
TO_DATE(str, fmt)TO_DATE(str, fmt) (verify format strings)
TO_NUMBER(str)CAST(str AS NUMERIC) or str::NUMERIC
`
DUAL tableRemove FROM DUAL; PostgreSQL evaluates SELECT expr without a table
CONNECT BY hierarchyRewrite using recursive CTEs (WITH RECURSIVE)
MERGE INTORewrite as INSERT ... ON CONFLICT DO UPDATE
Empty string '' as NULLOracle treats '' as NULL; PostgreSQL does not — check comparisons and IS NULL guards
VARCHAR2VARCHAR or TEXT

Step 7: Build and verify

After addressing all checklist items:

  1. Run dotnet build on the .Postgres project. Fix any remaining compilation errors.
  2. Verify no Oracle-specific namespaces remain: search for Oracle.ManagedDataAccess, OracleConnection, OracleCommand, :param patterns.
  3. Mark completed items in Reports/{ProjectName}/MigrationChecklist.md.

EF Core projects

If the project uses Oracle.EntityFrameworkCore:

  • Replace the provider registration in DbContext configuration: .UseOracle(...) → .UseNpgsql(...)
  • Replace OracleDbContextOptionsBuilder references.
  • Review OnModelCreating for Oracle-specific configurations (e.g., HasColumnType("NUMBER") → HasColumnType("numeric")).
  • Sequence configuration: modelBuilder.HasSequence<int>("seq_name").StartsAt(1).IncrementsBy(1) syntax is compatible; verify column defaults referencing sequences.
  • Do not run EF Core migrations — schema is managed externally via DDL scripts (Phase 4).

Key Constraints

  • Work only within the .Postgres copy — never modify the original Oracle-targeting project.
  • Keep to existing .NET and C# versions; do not introduce newer language or runtime features.
  • Preserve comments and application logic; change only what is necessary for PostgreSQL compatibility.
  • Oracle is the source of truth — behavioral differences must be documented as bug reports, not silently altered.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Map an existing codebase into seven documents covering its technology, structure, architecture, conventions, integrations, tests, and concerns. Link findings to file evidence, mark unknowns, and highlight differences between stated plans and the actual implementation.

中文简介正在准备中。当前显示英语简介。

  • Get oriented in an unfamiliar codebase
  • Prepare documentation for a project handover
  • Compare documented architecture with implementation
github/awesome-copilot4万2026年10月17日 更新

Assess a repository’s readiness for AI agents with AgentRC and generate a standalone HTML dashboard. Review scores across nine areas, see prioritized improvements, and optionally apply scoring policies tailored to an organization.

中文简介正在准备中。当前显示英语简介。

  • Assessing a repository’s readiness for AI agents
  • Prioritizing improvements from assessment results
  • Reviewing scores under an organization’s own policy
github/awesome-copilot4万2026年10月17日 更新

Generate coding agent instruction files from a project's actual code using AgentRC. Capture detected languages, frameworks, and conventions in one shared file or split rules by topic and project area, with a preview before writing.

中文简介正在准备中。当前显示英语简介。

  • Create project instructions for VS Code Copilot
  • Refresh agent rules after project changes
  • Split monorepo instructions by project area
github/awesome-copilot4万2026年10月17日 更新

Customize AgentRC readiness assessments to match team or organization standards. Choose or create policies that adjust check importance, disable irrelevant checks, set pass thresholds, and define requirements for automated checks in CI workflows.

中文简介正在准备中。当前显示英语简介。

  • Set shared readiness standards across an organization
  • Focus assessments on AI tooling
  • Adjust the importance of individual checks
github/awesome-copilot4万2026年10月17日 更新

Analyze supplied ad performance data to identify wasted spend, strong campaigns, and next tests. Compare channels, assess whether test differences are meaningful, and produce budget reallocation recommendations with a prioritized action plan.

中文简介正在准备中。当前显示英语简介。

  • Identify ads and keywords to pause
  • Find campaigns and audiences worth scaling
  • Assess whether A/B test results are meaningful
github/awesome-copilot4万2026年10月17日 更新

Turn code files into learning resources by adding comments that explain syntax, programming concepts, and design choices. Adjust explanation depth and repetition to the reader’s knowledge while preserving file structure, encoding, and syntax.

中文简介正在准备中。当前显示英语简介。

  • Add beginner-friendly explanations to existing code
  • Document the reasoning behind syntax and design choices
  • Adjust comment depth for readers with different experience
github/awesome-copilot4万2026年10月17日 更新

查看 github 的全部技能

报告此技能的问题