求助x.a= 1 and ((x.b= 1 and x.c=2) or (x.b= 1 and x.c=2) )写法 返回
SqlSugar
处理完成
4
270
glen 发布于1个月前
悬赏:0 飞吻
请问, 如何使用ConditionalModel和ConditionalCollections写出上面的sql, 谢谢
热忱回答(4)
-
glen VIP01个月前
var conModels = new List<IConditionalModel>(); conModels.Add(new ConditionalModel { FieldName = db.EntityMaintenance.GetDbColumnName<LocalizedProperty>(nameof(LocalizedProperty.LanguageId)), ConditionalType = ConditionalType.Equal, FieldValue = languageId.ToString(), CSharpTypeName = "long", }); conModels.Add(new ConditionalModel { FieldName = db.EntityMaintenance.GetDbColumnName<LocalizedProperty>(nameof(LocalizedProperty.LocaleKeyGroup)), ConditionalType = ConditionalType.Equal, FieldValue = localeKeyGroup, }); var conOtherModels = new List<IConditionalModel>(); // 循环查询localeKey和localeValue foreach (var item in filters) { conOtherModels.Add(new ConditionalCollections() { ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>() { new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel(){ FieldName = db.EntityMaintenance.GetDbColumnName<LocalizedProperty>(nameof(LocalizedProperty.LocaleKey)), ConditionalType=ConditionalType.Equal,FieldValue=item.FieldName}), new KeyValuePair<WhereType, ConditionalModel> ( WhereType.And, new ConditionalModel() {FieldName =db.EntityMaintenance.GetDbColumnName<LocalizedProperty>(nameof(LocalizedProperty.LocaleValue)),ConditionalType=ConditionalType.Like,FieldValue=item.Term.ToString()}), } }); } //var sql = db.Utilities.ConditionalModelsToSql(conOtherModels).ToString(); conModels.AddRange(ConditionalModel.Create(conOtherModels.ToArray()));
我是用上面的语句生成的是
x.a= 1 or (x.b= 1 and x.c=2) or (x.b= 1 and x.c=2)
无法实现:x.a= 1 and ((x.b= 1 and x.c=2) or (x.b= 1 and x.c=2) )
0 回复 -
fate sta VIP01个月前0 回复
-
fate sta VIP01个月前
根据json反序列列化出来的对象反推
应该是treeConditional 对象
0 回复 -
glen VIP01个月前
通过ConditionalTree解决了, 谢谢.
0 回复