public void SqlQueryTest() { var tableExp = new TableExp { Name = "Person", Exp = new GroupExp { Op = LogicalOp.And, Children = new List<Exp> { new ConditionExp { Op = FieldOp.Eq, Field = new ForeignField { Name = "Invitations", ForeignFieldName = "Id" }, Value = 1 } } } }; var toSql = Sql.From(tableExp); }
public static SqlQuery From(TableExp exp) { var query = new SqlQuery(); var whereQuery = exp.Exp.ToSql(query); var select = $"SELECT * FROM {exp.Name}"; var where = exp.Exp.Children.Count > 0 ? $"WHERE {whereQuery.Sql}" : ""; var sql = $"{select} {where}"; return new SqlQuery { Sql = sql, Params = whereQuery.Params }; }
private static Dictionary<string, object> SerializeTable(TableExp tbl) { return new Dictionary<string, object> { {"type", 0}, {"tableName", tbl.Name}, {"op", tbl.Exp.Op}, {"children", tbl.Exp.Children.Select(SerializeExpr)} }; }
public static string Serialize(TableExp tbl) { var obj = SerializeExpr(tbl); return JsonConvert.SerializeObject(obj); }
public void T1() { var c1 = new ConditionExp { Field = new Field { Name = "Id" }, Op = FieldOp.Gt, Value = 1 }; var c2 = new ConditionExp { Field = new Field { Name = "Name" }, Op = FieldOp.Contains, Value = "shai" }; var c3 = new ConditionExp { Field = new ForeignField { Name = "Invitations", ForeignFieldName = "Date" }, Op = FieldOp.Eq, Value = DateTime.Now.Date }; var group = new GroupExp { Op = LogicalOp.And, Children = new List<Exp> { c1, c2, c3 } }; var tbl = new TableExp { Name = "Person", Exp = group }; var db = new DB(ConString); var queryableData = db.Persons.AsQueryable(); var results = queryableData.From(tbl).ToArray(); }