Преглед изворни кода

修复UnitOfWork无法保存的BUG

zoule пре 4 месеци
родитељ
комит
484390dcf5

+ 0 - 3
DW5S.App/EditForms/RecEditor.cs

@@ -19,9 +19,6 @@ namespace DW5S.App.EditForms
 {
     public partial class RecEditor : DevExpress.XtraEditors.XtraForm
     {
-        
-        
-
         public TxInfo info;
         private List<TxInfo> infos;
         public RecEditor()

+ 2 - 0
DW5S.Entity/BaseEntity.cs

@@ -22,6 +22,7 @@ namespace DW5S.Entity
         /// <summary>
         /// 编号
         /// </summary>
+        [Key]
         public int Id { get; set; }
 
         /// <summary>
@@ -52,6 +53,7 @@ namespace DW5S.Entity
         /// <summary>
         /// 编号
         /// </summary>
+        [Key]
         public new long Id { get; set; }
     }
 }

+ 5 - 1
DW5S.Repostory/IocContainer.cs

@@ -32,7 +32,11 @@ namespace DW5S.Repostory
         {
             var scop = Container.BeginLifetimeScope();
             return scop.Resolve<T>();
-            //return Container.Resolve<T>();
+        }
+        public static T GetService<T>(object  parameter) where T : class
+        {
+            var scop = Container.BeginLifetimeScope();
+            return scop.Resolve<T>( new TypedParameter(parameter.GetType(), parameter));
         }
     }
 }

+ 1 - 1
DW5S.Repostory/Migrations/20250212082611_Init.Designer.cs → DW5S.Repostory/Migrations/20250212085549_Init.Designer.cs

@@ -12,7 +12,7 @@ using Oracle.EntityFrameworkCore.Metadata;
 namespace DW5S.Repostory.Migrations
 {
     [DbContext(typeof(OracleContext))]
-    [Migration("20250212082611_Init")]
+    [Migration("20250212085549_Init")]
     partial class Init
     {
         /// <inheritdoc />

+ 1 - 1
DW5S.Repostory/Migrations/20250212082611_Init.cs → DW5S.Repostory/Migrations/20250212085549_Init.cs

@@ -500,7 +500,7 @@ namespace DW5S.Repostory.Migrations
                 {
                     table.PrimaryKey("PK_CGXGFRES", x => x.ID);
                     table.ForeignKey(
-                        name: "FK_CGXGFRES_CGRES_CGRESID",
+                        name: "FK_CGXGFRES_CGRESID",
                         column: x => x.CGRESID,
                         principalTable: "CgRes",
                         principalColumn: "ID",

+ 3 - 2
DW5S.Repostory/UnitOfWork.cs

@@ -14,11 +14,12 @@ namespace DW5S.Repostory
     }
     public class UnitOfWork : IUnitOfWork
     {
-        private readonly OracleContext ctx;
+        public readonly OracleContext ctx;
 
         public IRepository<TEntity> Of<TEntity>() where TEntity : BaseEntity
         {
-            var reps = IocContainer.GetService<IRepository<TEntity>>();
+            //UnitOfWork中的DbContext必须和Repository中的DbContext是同一个对象
+            var reps = IocContainer.GetService<IRepository<TEntity>>(ctx);
             return reps;
         }