自定义表格查询 升级到 5.1.3.31-preview 版本发布 返回

SqlSugar 老数据
1 2188

 自定义表格查询

 List<IConditionalModel> conModels = new List<IConditionalModel>();
  //自定义
  conModels.Add(new ConditionalModel()
            {
                    FieldName = "name",
                    FieldValue = "1",
                    CustomConditionalFunc= new MyConditional()//赋值
                    //自定义字段 CustomParameterValue
 }); 
 //正常
 conModels.Add(new ConditionalModel() { FieldName = "id", ConditionalType = ConditionalType.Like, FieldValue = "1" });
 var list8=Db.Queryable<Order>().Where(conModels).ToList();
 
 
 //创建自定义
 public class MyConditional : ICustomConditionalFunc
 {
            public KeyValuePair<string,SugarParameter[]> GetConditionalSql(ConditionalModel conditionalModel,int index)
            {
                var parameterName= "@myp" + index;
                SugarParameter[] pars = new SugarParameter[] 
                {
                     new SugarParameter(parameterName, conditionalModel.FieldValue )
                };
                //自已处理字符串安全,也可以使用我自带的
                return new KeyValuePair<string, SugarParameter[]>
                    ($" { conditionalModel.FieldName.ToCheckRegexW() } = {parameterName}", pars);
            }
 }

升级到 5.1.3.31-preview 版本发布

热忱回答1

  • fate sta fate sta VIP0
    2022/11/3
        public class ConditionalModel: IConditionalModel
        {
            public ConditionalModel()
            {
                this.ConditionalType = ConditionalType.Equal;
            }
            public string FieldName { get; set; }
            public string FieldValue { get; set; }
            public string CSharpTypeName { get; set; }
            
    
            public ICustomConditionalFunc CustomConditionalFunc { get; set; }
            public dynamic CustomParameterValue { get; set; }
    
            public ConditionalType ConditionalType { get; set; }
            [Newtonsoft.Json.JsonIgnoreAttribute]
            public Func<string,object> FieldValueConvertFunc { get; set; }
        }


    0 回复