/// <summary> /// 解析条件 /// </summary> /// <param name="whereCompiler"></param> /// <returns></returns> public virtual void Translate(WhereCompilerInfo whereCompiler) { whereCompiler.Builder = new StringBuilder(); if (!string.IsNullOrEmpty(whereCompiler.Exp)) { AppendSql(whereCompiler); } var builder = new StringBuilder(); if (whereCompiler.IsSaveWhere) { var tableName = whereCompiler.SaveCompiler.SaveInfo.SetTableName; builder.Append("exists(select * from "); builder.Append(whereCompiler.GetJoinTable(whereCompiler.SaveCompiler.SaveInfo)); builder.AppendFormat(" where {0}.{1}={2}" , tableName, whereCompiler.Object.PrimaryProperty.FieldName , whereCompiler.GetFieldName(whereCompiler.Object.PrimaryProperty, null)); if (whereCompiler.Builder.Length > 0) { builder.Append(" and "); builder.Append(whereCompiler.Builder); } builder.Append(")"); whereCompiler.Builder = builder; } }
/// <summary> /// 转换1对多条件 /// </summary> /// <param name="whereCompiler"></param> /// <param name="property"></param> /// <param name="subText"></param> /// <param name="chainProperties"></param> /// <param name="propertyName"></param> /// <returns></returns> protected virtual WhereCompilerInfo GetSubWhereCompiler(WhereCompilerInfo whereCompiler, OrmPropertyInfo property, string subText, IList <OrmPropertyInfo> chainProperties, string propertyName) { var subWhereCompiler = new WhereCompilerInfo(property.Map.GetMapObject(), subText, new TableInfo { Joins = new Dictionary <string, JoinInfo>() }, new StringBuilder()) { Query = whereCompiler.Query }; Translate(subWhereCompiler); var lastIndex = propertyName.LastIndexOf('.'); if (lastIndex > -1) { propertyName = propertyName.Substring(0, lastIndex); } if (subWhereCompiler.Builder.Length > 0) { subWhereCompiler.Builder.Append(" and "); } subWhereCompiler.Builder.Insert(0, " where "); subWhereCompiler.Builder.Insert(0, string.Format("(select count(1) from {0} " , subWhereCompiler.GetJoinTable())); subWhereCompiler.Builder.AppendFormat("{0}={1})" , whereCompiler.GetFieldName(property.Map.ObjectProperty, propertyName) , subWhereCompiler.GetFieldName(property.Map.MapObjectProperty, null)); return(subWhereCompiler); }