private string BuildWhere <TResult>(string sqlTemplate, Expression <Func <TResult, bool> > expression, out object arguments) { var queryArgments = LamdaHelper.GetWhere <TResult>(expression); // Dictionary<string, object> dic = new Dictionary<string, object>(); dynamic args = new ExpandoObject(); StringBuilder where = new StringBuilder(); // where.Append("where "); // object arguments = new object(); string template = "{TableAlias}.{ColumnName} {Operator} @{ArgumentName} {Link} "; foreach (QueryArgument argument in queryArgments) { ((IDictionary <string, object>)args)[argument.Name] = argument.Value; string temp = template.Replace("{TableAlias}", aliasDic[argument.EntityType]); temp = temp.Replace("{ColumnName}", _dialectBuilder.GetColumn(argument.Name)); temp = temp.Replace("{Operator}", argument.Operator); temp = temp.Replace("{ArgumentName}", argument.ArgumentName); temp = temp.Replace("{Link}", argument.Link); where.Append(temp); } arguments = args; sqlTemplate = sqlTemplate.Replace("{WhereClause}", where.ToString()); return(sqlTemplate); }
public void TestWhere() { string value = "234" + "%"; Expression <Func <Category, bool> > exp = n => n.Id.Like(value) && n.Level == 2; var result = LamdaHelper.GetWhere <Category>(exp); Assert.AreEqual("11", "11"); }
public void TestWhere_constraint() { Category cat = new Category() { Id = "01", Name = "shp", FullName = "222", Level = 1 }; Expression <Func <Category, bool> > exp = n => n.Id.Like(cat.Id + "%") && n.Level == cat.Level; var result = LamdaHelper.GetWhere <Category>(exp); Assert.AreEqual("11", "11"); }
private string BuildWhere <TEntity>(System.Linq.Expressions.Expression <Func <TEntity, bool> > expression, out object arguments) { var queryArgments = LamdaHelper.GetWhere <TEntity>(expression); dynamic args = new ExpandoObject(); StringBuilder sql = new StringBuilder(); foreach (QueryArgument argument in queryArgments) { ((IDictionary <string, object>)args)[argument.ArgumentName] = argument.Value; sql.AppendFormat("{0} {1} @{2} {3} ", this._dialectBuilder.GetColumn(argument.Name), argument.Operator, argument.ArgumentName, argument.Link); } arguments = args; return(sql.ToString().Trim()); }