关于Insertable生成的执行sql字段转为nvarchar(4000)导致截断字符串的问题 返回

SqlSugar
3 140

代码:            


using (SqlSugarClient db = this.CreateDBClient(AppSetting.ConnectionString,))

            {

                    db.Insertable<Certificate>(certificate).ExecuteCommand();

            }



为何生成的sql,所有字段 转为 nvarchar(4000)而不是varchar??

 

exec sp_executesql N'INSERT INTO [Certificate]  

           ([BusinessSn],[CertificateTypeName],[CertificateTypeCode],[ApplyName],[ApplyDate],[ContactName],[CreditCode],[OwnerName],[LicenseCode],[LegalName],[LegalCertno],[TransCertificateCode],[VehicleNo],[PlateColorCode],[Telephone],[Sex],[CulturalLevel],[Address],[Company],[CompanyPhone],[IdType],[IdCard],[QuasiDriveTypeCode],[EarlyDate],[CertificateCode],[WorkTypeCode],[CertificateFirstIssueDate],[ApplyReason],[Reserved])

     VALUES

           (@BusinessSn,@CertificateTypeName,@CertificateTypeCode,@ApplyName,@ApplyDate,@ContactName,@CreditCode,@OwnerName,@LicenseCode,@LegalName,@LegalCertno,@TransCertificateCode,@VehicleNo,@PlateColorCode,@Telephone,@Sex,@CulturalLevel,@Address,@Company,@CompanyPhone,@IdType,@IdCard,@QuasiDriveTypeCode,@EarlyDate,@CertificateCode,@WorkTypeCode,@CertificateFirstIssueDate,@ApplyReason,@Reserved,@ZipArea) ;',N'@BusinessSn nvarchar(4000),@CertificateTypeName nvarchar(4000),@CertificateTypeCode nvarchar(4000),@ApplyName nvarchar(4000),@ApplyDate datetime,@ContactName nvarchar(4000),@CreditCode nvarchar(4000),@OwnerName nvarchar(4000),@LicenseCode nvarchar(4000),@LegalName nvarchar(4000),@LegalCertno nvarchar(4000),@TransCertificateCode nvarchar(4000),@VehicleNo nvarchar(4000),@PlateColorCode nvarchar(4000),@Telephone nvarchar(4000),@Sex nvarchar(4000),@CulturalLevel nvarchar(4000),@Address nvarchar(4000),@Company nvarchar(4000),@CompanyPhone nvarchar(4000),@IdType nvarchar(4000),@IdCard nvarchar(4000),@QuasiDriveTypeCode nvarchar(4000),@EarlyDate datetime,@CertificateCode nvarchar(4000),@WorkTypeCode nvarchar(4000),@CertificateFirstIssueDate datetime,@ApplyReason nvarchar(4000),@Reserved nvarchar(4000)',@BusinessSn=N'450100GXT202109150000028',@CertificateTypeName=N'证',@CertificateTypeCode=N'11100000000019713D008',@ApplyName=N'张三',@ApplyDate='2021-01-01 00:00:00',@ContactName=N'张三',@CreditCode=N'wehfwe9y927397e20022',@OwnerName=N'xxx',@LicenseCode=N'450128100001',@LegalName=N'李十九',@LegalCertno=N'15878152527',@TransCertificateCode=NULL,@VehicleNo=NULL,@PlateColorCode=NULL,@Telephone=N'18278161128',@Sex=NULL,@CulturalLevel=NULL,@Address=NULL,@Company=NULL,@CompanyPhone=NULL,@IdType=NULL,@IdCard=NULL,@QuasiDriveTypeCode=NULL,@EarlyDate=NULL,@CertificateCode=NULL,@WorkTypeCode=NULL,@CertificateFirstIssueDate=NULL,@ApplyReason=NULL,@Reserved=N'保留'



导致报错:



消息 8152,级别 16,状态 2,第 1 行

将截断字符串或二进制数据。

语句已终止。




热忱回答3

  • 这个错是你的数据库字段小了

    0 回复
  • 你也可以全部配置成varahar 

    db.CurrentConnectionConfig.MoreSettings=new MoreSettings(){DisableNvarchar=true};

    0 回复
  • 张新亮 张新亮 VIP0
    1个月前

    @fate stay night:谢谢

    0 回复