Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用Uow,执行ExecuteOracleBulkCopy不会回滚事务,使用ExecuteAffrows会回滚 #1968

Open
ZhuHJie opened this issue Jan 21, 2025 · 1 comment

Comments

@ZhuHJie
Copy link

ZhuHJie commented Jan 21, 2025

  1. 是使用Uow,执行ExecuteOracleBulkCopy不会回滚事务,使用ExecuteAffrows会回滚

  2. update模式使用bulkcopy会报错

问题出于生成时间类型DATE(7)
Image

CREATE GLOBAL TEMPORARY TABLE "TEMP_EDC225FC5E84407DA8085073" (  
  "ID" VARCHAR2(18 CHAR), 
  "DATETIME_CREATED" DATE(7), 
  "DATETIME_MODIFIED" DATE(7), 
  "DENOMINATOR_QTY" NUMBER(18,6) , 
  "ENTERPRISE_ID" VARCHAR2(18 CHAR) , 
  "ERP_BOM_ID" VARCHAR2(40 CHAR), 
  "ERP_ROW_ID" VARCHAR2(80 BYTE), 
  "MD006" VARCHAR2(100 BYTE), 
  "MD007" VARCHAR2(100 BYTE), 
  "MD019" VARCHAR2(2000 BYTE), 
  "MD020" VARCHAR2(100 BYTE), 
  "MD021" VARCHAR2(100 BYTE), 
  "MD022" VARCHAR2(100 BYTE), 
  "MITEM_CODE" VARCHAR2(40 CHAR) , 
  "MITEM_DESC" VARCHAR2(1000 CHAR), 
  "MITEM_ID" VARCHAR2(18 CHAR) , 
  "MITEM_NAME" VARCHAR2(120 CHAR), 
  "MITEM_TYPE" VARCHAR2(200 BYTE), 
  "MO_CODE" VARCHAR2(40 CHAR) , 
  "MO_REQUEST_QTY" NUMBER(18,6) , 
  "MO_TYPE_CODE" VARCHAR2(80 BYTE), 
  "NUMERATOR_QTY" NUMBER(18,6) , 
  "ORG_ID" VARCHAR2(18 CHAR) , 
  "PARENT_MITEM_CODE" VARCHAR2(80 BYTE), 
  "PARENT_MITEM_ID" VARCHAR2(36 BYTE), 
  "PROGRAM_BOM" VARCHAR2(80 BYTE), 
  "ROUTING_NODE_CODE" VARCHAR2(80 BYTE), 
  "ROUTING_NODE_NAME" VARCHAR2(240 BYTE), 
  "STATE" CHAR(1 BYTE) , 
  "TB006" VARCHAR2(100 BYTE), 
  "UOM" VARCHAR2(40 CHAR) , 
  "USER_CREATED" VARCHAR2(40 CHAR) , 
  "USER_MODIFIED" VARCHAR2(40 CHAR)
) ON COMMIT PRESERVE ROWS

代码

  [Fact]
        public void SyncBoms()
        {
            int acceptDay = 5;
            using (var mesUnitOfWork = DbHelper.MesDb.CreateUnitOfWork())
            {
                try
                {
                    ISyncMoBom syncMoBom = new SyncMoBom(mesUnitOfWork);
                    var modifiedMoBoms = syncMoBom.GetModifiedMoBoms(acceptDay);
                    var allMoBoms = new List<SFC_MO_BOM>();
                    if (
                        modifiedMoBoms.UpdateMoBoms != null
                        && modifiedMoBoms.UpdateMoBoms!.Count > 0
                    )
                    {
                        allMoBoms.AddRange(modifiedMoBoms.UpdateMoBoms);
                        mesUnitOfWork
                            .Orm.Update<SFC_MO_BOM>()
                            .SetSource(modifiedMoBoms.UpdateMoBoms)
                            .ExecuteOracleBulkCopy();
                    }
                    if (
                        modifiedMoBoms.InsertMoBoms != null
                        && modifiedMoBoms.InsertMoBoms!.Count > 0
                    )
                    {
                        allMoBoms.AddRange(modifiedMoBoms.InsertMoBoms);
                        mesUnitOfWork
                            .Orm.Insert<SFC_MO_BOM>(modifiedMoBoms.InsertMoBoms)
                            .ExecuteOracleBulkCopy();
                    }

                    var lts = allMoBoms
                        .Select(e => new
                        {
                            e.MO_TYPE_CODE,
                            e.MO_CODE,
                            e.MITEM_CODE
                        })
                        .ToList();
                    var modifiedCount = mesUnitOfWork
                        .Orm.Select<SFC_MO_BOM>()
                        .Where(e =>
                            lts.Any(l =>
                                l.MO_TYPE_CODE == e.MO_TYPE_CODE
                                && l.MO_CODE == e.MO_CODE
                                && l.MITEM_CODE == e.MITEM_CODE
                            )
                        )
                        .Count();

                    modifiedCount.ShouldBe(allMoBoms.Count);
                }
                catch (System.Exception)
                {
                    throw;
                }
                finally
                {
                    mesUnitOfWork.Rollback(); //事务回滚
                }
            }
        }

数据库版本

oracle 11g

安装的Nuget包

<PackageReference Include="FreeSql" Version="3.5.104" />
	<PackageReference Include="FreeSql.DbContext" Version="3.5.104" />
	<PackageReference Include="FreeSql.Provider.Oracle" Version="3.5.104" />

.net 8

@2881099
Copy link
Collaborator

2881099 commented Jan 22, 2025

bulkcopy 操作不能用事务

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants