【ASP.NET Core × Oracle】實作:透過 Entity Framework Core 映射 Oracle 資料表

在開發企業內部系統的時候,我們經常需要將 .NET 應用程式連結至 Oracle 資料庫,以便讀寫現有的業務資料。這篇文章將示範如何透過 Entity Framework Core 對 Oracle 中的資料表(以 APS_Z_PLAN 為例)建立對應的 Model 類別,讓後續開發更為順暢。

🧩 Entity Model 範例

以下範例僅列出幾個具代表性的屬性,讓你掌握 EF Core 映射資料表的核心技巧:

  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. namespace Net.Model
  5. {
  6. public class APSZPLAN
  7. {
  8. [Key]
  9. [Column("APS_PLAN_NO")]
  10. public string APS_PLAN_NO { get; set; } = string.Empty; // 方案編號
  11. public string? DOC_NO { get; set; } // 急單編號(可為空)
  12. [Key]
  13. [Column("APS_PLAN_SEQ")]
  14. public decimal APS_PLAN_SEQ { get; set; } // 複合主鍵 - 序號
  15. public decimal? APS_PLAN_LIST { get; set; } // 方案列表(可為空)
  16. public DateTime? ORI_PLAN_DATE { get; set; } // 原始計劃日期(可為空)
  17. public string? REMARK { get; set; } // 備註
  18. }
  19. }

留言

這個網誌中的熱門文章

🔍Vue.js 專案錯誤排查:解決 numericFields is not defined 與合併儲存格邏輯最佳化

🔎EF Core 連 Oracle 出現 ORA-00600 [kpp_concatq:2] 的完整排錯指南(含 EF Core ToString/CultureInfo 錯誤)

🛠【ASP.NET Core + Oracle】解決 ORA-00904 "FALSE": 無效的 ID 錯誤與資料欄位動態插入顯示問題