コード例 #1
0
        public virtual string ListToLiteral(object value, DbTypeDef elemTypeDef)
        {
            var list = value as IList;

            if (list.Count == 0)
            {
                return(GetEmptyListLiteral(elemTypeDef));
            }
            var strList = new List <string>(list.Count);

            foreach (var item in list)
            {
                strList.Add(elemTypeDef.ToLiteral(item));
            }
            return(string.Join(", ", strList));
        }
コード例 #2
0
ファイル: PgSqlDialect.cs プロジェクト: radtek/vita
        /*
         * We are using Any() function for in-array operator (instead of standard SQL's '<value> IN <list>)
         * Any() works both for parameter (as list value) or list literal. But list literal must be formatted using
         * ARRAY[..] method. Example of correct query with literal:
         *
         *  Select *
         *  from "books"."Book"
         *  WHERE "Title" = Any(ARRAY['IronMan', 'Windows Programming'])
         *    or "Category" = Any(ARRAY[0,1])
         *    OR "Category" = Any('{}') -- empty array
         *
         */
        public override string ListToLiteral(object value, DbTypeDef elemTypeDef)
        {
            var list = value as IList;

            if (list.Count == 0)
            {
                return("'{}'"); // GetEmptyListLiteral(elemTypeDef);
            }
            var strList = new List <string>(list.Count);

            foreach (var item in list)
            {
                strList.Add(elemTypeDef.ToLiteral(item));
            }
            return("ARRAY[" + string.Join(", ", strList) + "]");
        }