Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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
            };
        }
Ejemplo n.º 3
0
 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)}
     };
 }
Ejemplo n.º 4
0
 public static string Serialize(TableExp tbl)
 {
     var obj = SerializeExpr(tbl);
     return JsonConvert.SerializeObject(obj);
 }
Ejemplo n.º 5
0
        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();
        }