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

InsertOrUpdate函数在更新数据时出现映射sql丢失问题 #1630

Closed
NicJX opened this issue Sep 27, 2023 · 1 comment
Closed

InsertOrUpdate函数在更新数据时出现映射sql丢失问题 #1630

NicJX opened this issue Sep 27, 2023 · 1 comment

Comments

@NicJX
Copy link

NicJX commented Sep 27, 2023

问题描述及重现代码:

问题描述:同步情况下,数据库某条数据已存在的时候,InsertOrUpdate函数在执行时候映射生成的sql 时,会出现
“2023-09-27 17:56:22 8811 线程ID[4]->UPDATE [RIS_WORKLIST] SET ” 这情况,丢失了set后面的部分语句,报错提示:‘set’ 附近有语法错误”。
做过测试,在数据库数据与实体某个字段数据不同的时候就能正常保存成功,生成语句也正常。

// c# code
//使用IdleBus主要是同时要链接多个库
//程序集IdleBus, Version=1.5.2.0, Culture=neutral, PublicKeyToken=c3451542aabc4510
    public class DbBus : IdleBus<DbName, IFreeSql>
    {
        public DbBus() : base(TimeSpan.FromMinutes(30)) { }
    }

servic:
public class TestService{
  DbBus _dbs;

 public TestService(DbBus dbs)
        { 
            _dbs = dbs;
        }

 public int SaveEBHData(EBH_RisFee risFee, EBH_RisWorkList risWorkListInfo,EBH_RisRequest risRequest, DbName dbName)
        { 
            var success = 0;
            var fsql = _dbs.Get(dbName);
            using (var uow = fsql.CreateUnitOfWork())
            {
                try
                {  
                    var risFeeRepo = fsql.GetRepository<EBH_RisFee>();
                    risFeeRepo.UnitOfWork = uow;

                    var risWorkListRepo = fsql.GetRepository<EBH_RisWorkList>();
                    risWorkListRepo.UnitOfWork = uow;

                    var risRequestRepo = fsql.GetRepository<EBH_RisRequest>();
                    risRequestRepo.UnitOfWork = uow;
                      
                      risFeeRepo.InsertOrUpdate(risFee); 
                    risWorkListRepo.InsertOrUpdate(risWorkListInfo); 
                     risRequestRepo.InsertOrUpdate(risRequest);
                    uow.Commit();
                    success = 1;
                }
                catch (Exception ex)
                {
                    uow.Rollback(); 
                }
            }
            return success;

        }
}

 [JsonObject(MemberSerialization.OptIn), Table(Name = "RIS_WORKLIST")]
    public  class EBH_RisWorkList
    {
		[JsonProperty, Column(DbType = "varchar(64)", IsPrimary = true)]
		public string RequisitionID { get; set; }

		[JsonProperty, Column(Name = "accession_number", DbType = "varchar(32)")]
		public string Accession_number { get; set; }

		[JsonProperty, Column(DbType = "varchar(128)")]
		public string Address { get; set; }

		[JsonProperty]
		public int? AFCID { get; set; }

		[JsonProperty, Column(IsIdentity = true)]
		public int AutoIndex { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string Birthday { get; set; }

		[JsonProperty, Column(DbType = "varchar(8)")]
		public string BirthTime { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string CertificateID { get; set; }

		[JsonProperty, Column(DbType = "varchar(512)")]
		public string CheckSTDescribed { get; set; }

		[JsonProperty, Column(DbType = "varchar(2048)")]
		public string ClinicDiagnose { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string ClinicID { get; set; }

		[JsonProperty]
		public int? Confidentiality { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string CustomCheckNumber { get; set; }

		[JsonProperty]
		public int DepartmentID { get; set; }

		[JsonProperty]
		public int EmergencyID { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string EndoscopyType { get; set; }

		[JsonProperty, Column(DbType = "varchar(128)")]
		public string ExamBodyPart { get; set; }

		[JsonProperty]
		public int? ExamBodyPartNum { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string ExamDate { get; set; }

		[JsonProperty, Column(DbType = "varchar(128)")]
		public string ExamMethod { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string ExamParameter { get; set; }

		[JsonProperty, Column(Name = "exampath", DbType = "varchar(50)")]
		public string Exampath { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string ExamTime { get; set; }

		[JsonProperty, Column(DbType = "varchar(128)")]
		public string FamilyTelephe { get; set; }

		[JsonProperty, Column(DbType = "varchar(64)")]
		public string FeeTypeName { get; set; }

		[JsonProperty]
		public int? FollowFlag { get; set; }

		[JsonProperty]
		public int? HaveImage { get; set; }

		[JsonProperty]
		public int? HaveRemark { get; set; }

		[JsonProperty, Column(DbType = "varchar(50)")]
		public string HospitalAreaName { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string HospitalID { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string ImageName { get; set; }

		[JsonProperty, Column(DbType = "varchar(128)")]
		public string ImagePath { get; set; }

		[JsonProperty, Column(Name = "imagequality", DbType = "varchar(32)")]
		public string Imagequality { get; set; }

		[JsonProperty]
		public int? InAdvanceQueue { get; set; }

		[JsonProperty]
		public int? InDeedQueue { get; set; }

		[JsonProperty, Column(Name = "isAddPatient", DbType = "varchar(2)")]
		public string IsAddPatient { get; set; }

		[JsonProperty, Column(Name = "isChangeDate", DbType = "varchar(2)")]
		public string IsChangeDate { get; set; }

		[JsonProperty, Column(Name = "isIBD", DbType = "varchar(2)")]
		public string IsIBD { get; set; }

		[JsonProperty]
		public int? IsNotCallNumber { get; set; }

		[JsonProperty]
		public int? IsNotNOScreen { get; set; }

		[JsonProperty, Column(Name = "isOverTime", DbType = "varchar(2)")]
		public string IsOverTime { get; set; }

		[JsonProperty]
		public int? IsPaSSNumber { get; set; }

		[JsonProperty, Column(Name = "isSEZCJ", DbType = "varchar(2)")]
		public string IsSEZCJ { get; set; }

		[JsonProperty]
		public int IsSpePatientSign { get; set; }

		[JsonProperty]
		public int? IsTexu { get; set; }

		[JsonProperty, Column(Name = "isZhiLiao", DbType = "varchar(2)")]
		public string IsZhiLiao { get; set; }

		[JsonProperty]
		public DateTime? LastTryForImage { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string MedicalCardNumber { get; set; }

		[JsonProperty, Column(DbType = "varchar(4096)")]
		public string MedicalHistory { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string MIcardNumber { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string ModalityAE { get; set; }

		[JsonProperty]
		public int? ModalityID { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string ModalityName { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string ModalityRemark { get; set; }

		[JsonProperty]
		public int? ModalityRoomID { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string ModalityType { get; set; }

		[JsonProperty]
		public int? NurseStationFlag { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string PathologicID { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string PatientID { get; set; }

		[JsonProperty]
		public int PatientTypeID { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string PhysicalExamID { get; set; }

		[JsonProperty, Column(DbType = "varchar(128)")]
		public string PhysicianRequirements { get; set; }

		[JsonProperty]
		public int PrintFlag { get; set; }

		[JsonProperty]
		public int? PrintNoticeFlag { get; set; }

		[JsonProperty, Column(DbType = "varchar(128)")]
		public string PTN_NAME { get; set; }

		[JsonProperty, Column(DbType = "varchar(128)")]
		public string PY { get; set; }

		[JsonProperty]
		public int QueueStateID { get; set; }

		[JsonProperty, Column(DbType = "varchar(2048)")]
		public string Remarks { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string ReqDepartment { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string ReqHospital { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string ReqPhysician { get; set; }

		[JsonProperty]
		public int? ResourceID { get; set; }

		[JsonProperty]
		public int? SendRepFlag { get; set; }

		[JsonProperty, Column(Name = "SEX", DbType = "varchar(32)")]
		public string Sex { get; set; }

		[JsonProperty, Column(DbType = "varchar(50)")]
		public string SickbedID { get; set; }

		[JsonProperty]
		public int? StateID { get; set; }

		[JsonProperty]
		public int? StationID { get; set; }

		[JsonProperty, Column(DbType = "varchar(32)")]
		public string Telephone { get; set; }

		[JsonProperty]
		public double? Weight { get; set; }

		[JsonProperty, Column(DbType = "varchar(128)")]
		public string WorkStationAddress { get; set; }


	}

数据库版本

mssql

安装的Nuget包

FreeSql 3.2.801
FreeSql.Provider.SqlServer 3.2.801
FreeSql.Repository 3.2.801
IdleBus 1.5.2

.net framework/. net core? 及具体版本

net core 3.1

@2881099
Copy link
Collaborator

2881099 commented Oct 9, 2023

		[JsonProperty, Column(IsIdentity = true)]
		public int AutoIndex { get; set; }

忽略之前的更新。
这个属性引起的,数据库中的值是1,.net中的值是0

解决办法:

		[JsonProperty, Column(IsIdentity = true, CanUpdate = false)]
		public int AutoIndex { get; set; }

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